From eaeb08820499c6cf1b821e02a5d14470acc4cfae Mon Sep 17 00:00:00 2001 From: Aleksandr Tcitlionok <803797+terghalin@users.noreply.github.com> Date: Thu, 5 Dec 2024 08:35:00 +0000 Subject: [PATCH] fix(think): revert --- app/routes/think.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/app/routes/think.py b/app/routes/think.py index 67daf3e..8347b96 100644 --- a/app/routes/think.py +++ b/app/routes/think.py @@ -1,3 +1,40 @@ +from fastapi import APIRouter, HTTPException +from kubernetes import client, config +from typing import List, Dict +import requests +import os + +router = APIRouter() + +def fetch_ai_summary(cluster_name: str, nodes: List[Dict], api_url: str, auth_token: str) -> str: + """ + Sends node data to an external AI API endpoint and retrieves a summary response. + """ + payload = { + "data": { + "cluster_name": cluster_name, + "nodes": nodes + } + } + + headers = { + "Authorization": f"Bearer {auth_token}", + "Content-Type": "application/json" + } + + try: + response = requests.post(api_url, json=payload, headers=headers) + if response.status_code == 200: + result = response.json() + if result.get("success"): + return result.get("result", "No result provided by the API.") + else: + return "API responded with success=false." + else: + return f"API request failed with status code {response.status_code}: {response.text}" + except requests.RequestException as e: + return f"An error occurred while contacting the API: {str(e)}" + @router.get("/think/k8s") def think_k8s(): """ @@ -35,3 +72,4 @@ def think_k8s(): summary = fetch_ai_summary(cluster_name, nodes, api_url, auth_token) return {"summary": summary} +