Download app/routers/health.py from acpcchatbotadmin/acpcchatbot_testing_first: direct link, hf CLI and curl.
- Browser
- Download file 2.49 kB
-
https://huggingface.co/spaces/acpcchatbotadmin/acpcchatbot_testing_first/resolve/main/app/routers/health.py
- Command line
-
hf download hf://spaces/acpcchatbotadmin/acpcchatbot_testing_first/app/routers/health.py
-
curl -L -o health.py https://huggingface.co/spaces/acpcchatbotadmin/acpcchatbot_testing_first/resolve/main/app/routers/health.py
2.49 kB
| import time | |
| import logging | |
| from fastapi import APIRouter | |
| from app.schemas.health import HealthResponse, DetailedHealthResponse, ComponentStatus | |
| from app.memory.session_store import active_session_count | |
| from app.config import settings | |
| router = APIRouter(prefix="/api", tags=["health"]) | |
| logger = logging.getLogger(__name__) | |
| _start_time = time.time() | |
| async def health(): | |
| """Basic health check.""" | |
| from app.agent.graph import _compiled_graph | |
| from app.retrieval.qdrant_store import _client | |
| return HealthResponse( | |
| status="ok", | |
| agent_ready=_compiled_graph is not None, | |
| qdrant_connected=_client is not None, | |
| active_sessions=active_session_count(), | |
| ) | |
| async def health_detailed(): | |
| """Detailed per-component health check.""" | |
| components: dict[str, ComponentStatus] = {} | |
| # Check Qdrant | |
| try: | |
| from app.retrieval.qdrant_store import get_qdrant_client | |
| client = get_qdrant_client() | |
| info = client.get_collection(settings.collection_name) | |
| components["qdrant"] = ComponentStatus( | |
| status="ok", | |
| detail=f"collection={settings.collection_name}, points={info.points_count}", | |
| ) | |
| except Exception as e: | |
| components["qdrant"] = ComponentStatus(status="error", detail=str(e)) | |
| # Check OpenAI (ping model list) | |
| try: | |
| from openai import OpenAI | |
| c = OpenAI(api_key=settings.openai_api_key) | |
| c.models.retrieve(settings.llm_model) | |
| components["openai"] = ComponentStatus(status="ok", detail=f"model={settings.llm_model}") | |
| except Exception as e: | |
| components["openai"] = ComponentStatus(status="error", detail=str(e)) | |
| # Sarvam (just check key is configured) | |
| components["sarvam"] = ComponentStatus( | |
| status="ok" if settings.sarvam_api_key else "unconfigured", | |
| ) | |
| # Langfuse (check key is configured) | |
| components["langfuse"] = ComponentStatus( | |
| status="ok" if settings.langfuse_public_key else "unconfigured", | |
| ) | |
| all_ok = all(c.status == "ok" for c in components.values()) | |
| return DetailedHealthResponse( | |
| status="ok" if all_ok else "degraded", | |
| components=components, | |
| uptime_seconds=time.time() - _start_time, | |
| active_sessions=active_session_count(), | |
| ) | |