from __future__ import annotations import logging from fastapi import APIRouter from fastapi.responses import JSONResponse from app.clients.hana_client import hana_client from app.config import settings from app.services.model_status import check_all_model_statuses LOG = logging.getLogger(__name__) router = APIRouter() @router.get("/models") async def get_models(): """Return available Neon models (fresh from HANA) and comparison providers.""" try: neon_models = await hana_client.get_models() except Exception as exc: LOG.warning("HANA unavailable — Neon models will be empty: %s", exc) neon_models = [] comparison_providers = [] for p in settings.comparison_providers: comparison_providers.append({ "id": p["id"], "name": p["name"], "models": p["models"], }) return JSONResponse( content={ "neon_models": neon_models, "comparison_providers": comparison_providers, }, headers={"Cache-Control": "no-store"}, ) @router.get("/models/status") async def get_models_status(): """Probe each model with a tiny chat request and return online/unavailable/error.""" statuses = await check_all_model_statuses() return JSONResponse( content={"statuses": statuses}, headers={"Cache-Control": "no-store"}, )