fix(think): revert
This commit is contained in:
@@ -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")
|
@router.get("/think/k8s")
|
||||||
def think_k8s():
|
def think_k8s():
|
||||||
"""
|
"""
|
||||||
@@ -35,3 +72,4 @@ def think_k8s():
|
|||||||
summary = fetch_ai_summary(cluster_name, nodes, api_url, auth_token)
|
summary = fetch_ai_summary(cluster_name, nodes, api_url, auth_token)
|
||||||
|
|
||||||
return {"summary": summary}
|
return {"summary": summary}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user