ai: route all chat through atlasbot

This commit is contained in:
Brad Stein 2026-01-27 14:54:35 -03:00
parent d087558c22
commit aec391608d

View File

@ -28,7 +28,6 @@ def register(app) -> None:
if atlasbot_reply:
elapsed_ms = int((time.time() - started) * 1000)
return jsonify({"reply": atlasbot_reply, "latency_ms": elapsed_ms, "source": "atlasbot"})
if _requires_atlasbot(user_message):
elapsed_ms = int((time.time() - started) * 1000)
return jsonify(
{
@ -38,31 +37,6 @@ def register(app) -> None:
}
)
messages: list[dict[str, str]] = []
if settings.AI_CHAT_SYSTEM_PROMPT:
messages.append({"role": "system", "content": settings.AI_CHAT_SYSTEM_PROMPT})
for item in history:
role = item.get("role")
content = (item.get("content") or "").strip()
if role in ("user", "assistant") and content:
messages.append({"role": role, "content": content})
messages.append({"role": "user", "content": user_message})
body = {"model": settings.AI_CHAT_MODEL, "messages": messages, "stream": False}
try:
with httpx.Client(timeout=settings.AI_CHAT_TIMEOUT_SEC) as client:
resp = client.post(f"{settings.AI_CHAT_API}/api/chat", json=body)
resp.raise_for_status()
data = resp.json()
reply = (data.get("message") or {}).get("content") or ""
elapsed_ms = int((time.time() - started) * 1000)
return jsonify({"reply": reply, "latency_ms": elapsed_ms})
except (httpx.RequestError, httpx.HTTPStatusError, ValueError) as exc:
return jsonify({"error": str(exc)}), 502
@app.route("/api/chat/info", methods=["GET"])
@app.route("/api/ai/info", methods=["GET"])
def ai_info() -> Any:
@ -90,25 +64,6 @@ def _atlasbot_answer(message: str) -> str:
except (httpx.RequestError, ValueError):
return ""
def _requires_atlasbot(message: str) -> bool:
text = (message or "").lower()
hints = (
"atlas",
"titan",
"cluster",
"node",
"nodes",
"pod",
"pods",
"postgres",
"database",
"grafana",
"victoria",
"metrics",
)
return any(hint in text for hint in hints)
def _discover_ai_meta() -> dict[str, str]:
meta = {
"node": settings.AI_NODE_NAME,