Source code for api_gateway.routers.config
"""
Config Router
Exposes read-only system configuration (active models, service info).
"""
import logging
from typing import Optional
import httpx
from fastapi import APIRouter, HTTPException, Request
from lalandre_core.config import get_config
logger = logging.getLogger(__name__)
router = APIRouter(prefix="/api/v1", tags=["config"])
[docs]
@router.get("/config")
async def get_system_config(request: Request) -> dict:
"""
Return read-only system configuration: active models and service info.
Calls downstream services to retrieve live info where available.
"""
embedding_service_url: Optional[str] = getattr(request.app.state, "embedding_service_url", None)
rerank_service_url: Optional[str] = getattr(request.app.state, "rerank_service_url", None)
rag_service_url: Optional[str] = getattr(request.app.state, "rag_service_url", None)
timeout = get_config().gateway.healthcheck_timeout_seconds
embedding_info = None
rerank_info = None
generation_info = None
search_info = None
if embedding_service_url:
try:
async with httpx.AsyncClient(timeout=timeout) as client:
resp = await client.get(f"{embedding_service_url}/info")
if resp.status_code == 200:
embedding_info = resp.json()
except Exception as e:
logger.warning("Could not fetch embedding service info: %s", e)
if rerank_service_url:
try:
async with httpx.AsyncClient(timeout=timeout) as client:
resp = await client.get(f"{rerank_service_url}/health")
if resp.status_code == 200:
health_data = resp.json()
rerank_info = {
"status": "available",
"model": health_data.get("model"),
}
except Exception as e:
logger.warning("Could not fetch rerank service info: %s", e)
if rag_service_url:
try:
async with httpx.AsyncClient(timeout=timeout) as client:
resp = await client.get(f"{rag_service_url}/config")
if resp.status_code == 200:
data = resp.json()
generation_info = data.get("generation")
search_info = data.get("search")
except Exception as e:
logger.warning("Could not fetch RAG config: %s", e)
return {
"embedding": embedding_info,
"rerank": rerank_info,
"generation": generation_info,
"search": search_info,
}
[docs]
@router.post("/rerank/reload")
async def reload_rerank(request: Request) -> dict:
"""Proxy reload request to the rerank service."""
rerank_url: Optional[str] = getattr(request.app.state, "rerank_service_url", None)
if not rerank_url:
raise HTTPException(status_code=404, detail="Rerank service not configured")
try:
async with httpx.AsyncClient(timeout=get_config().gateway.rag_proxy_timeout_seconds) as client:
resp = await client.post(f"{rerank_url}/reload")
if resp.status_code != 200:
raise HTTPException(status_code=resp.status_code, detail=resp.text)
return resp.json()
except httpx.RequestError as e:
raise HTTPException(status_code=503, detail=f"Rerank service unreachable: {e}")