Add Ollama health check status indicator to chat views
Adds visibility into whether Ollama is reachable and the configured model is ready before allowing chat. Prevents silent failures when the model is still downloading or Ollama is unavailable. - Backend: GET /api/chat/status endpoint checks Ollama /api/tags (5s timeout) Returns ollama availability + model readiness + default model name - Frontend: OllamaStatus type, chat store polling (30s interval) - ChatView: status dot + label in header (green/yellow/red), disabled send - ChatPanel: compact status indicator in panel header, disabled send - summary.md: updated with new endpoint, store changes, and component descriptions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import json
|
||||
import logging
|
||||
|
||||
import httpx
|
||||
from quart import Blueprint, Response, jsonify, request
|
||||
|
||||
from fabledassistant.config import Config
|
||||
@@ -156,10 +157,32 @@ async def summarize_conversation_route(conv_id: int):
|
||||
return jsonify({"error": str(e)}), 400
|
||||
|
||||
|
||||
@chat_bp.route("/status", methods=["GET"])
|
||||
async def chat_status_route():
|
||||
"""Check Ollama availability and model readiness."""
|
||||
default_model = Config.OLLAMA_MODEL
|
||||
result = {
|
||||
"ollama": "unavailable",
|
||||
"model": "not_found",
|
||||
"default_model": default_model,
|
||||
}
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=5.0) as client:
|
||||
resp = await client.get(f"{Config.OLLAMA_URL}/api/tags")
|
||||
resp.raise_for_status()
|
||||
result["ollama"] = "available"
|
||||
data = resp.json()
|
||||
model_names = [m["name"] for m in data.get("models", [])]
|
||||
# Match with or without :latest tag
|
||||
if default_model in model_names or f"{default_model}:latest" in model_names:
|
||||
result["model"] = "ready"
|
||||
except Exception:
|
||||
logger.debug("Ollama status check failed", exc_info=True)
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
@chat_bp.route("/models", methods=["GET"])
|
||||
async def list_models_route():
|
||||
import httpx
|
||||
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10.0) as client:
|
||||
resp = await client.get(f"{Config.OLLAMA_URL}/api/tags")
|
||||
|
||||
Reference in New Issue
Block a user