Live AI provider/model switching without restart
Backend: - RuntimeAIConfig singleton: mutable in-memory overrides for provider/model - PATCH /admin/api/ai/config: change active provider/model on the fly - GET /admin/api/ai/config: read current runtime state - ai_vision.py: uses runtime_ai_config before falling back to settings - health/status endpoints reflect runtime overrides Frontend: - 'Définir comme actif' button in AI config section - Live feedback message on save
This commit is contained in:
+9
-4
@@ -188,15 +188,20 @@ async def root():
|
||||
|
||||
@app.get("/health", tags=["Santé"])
|
||||
async def health():
|
||||
from app.services.runtime_config import runtime_ai_config
|
||||
active_provider = runtime_ai_config.provider or settings.AI_PROVIDER
|
||||
active_model = runtime_ai_config.model or (
|
||||
settings.OPENROUTER_MODEL if active_provider == "openrouter"
|
||||
else settings.GEMINI_MODEL
|
||||
)
|
||||
ai_configured = (
|
||||
(settings.AI_PROVIDER == "gemini" and bool(settings.GEMINI_API_KEY)) or
|
||||
(settings.AI_PROVIDER == "openrouter" and bool(settings.OPENROUTER_API_KEY))
|
||||
(active_provider == "gemini" and bool(settings.GEMINI_API_KEY)) or
|
||||
(active_provider == "openrouter" and bool(settings.OPENROUTER_API_KEY))
|
||||
)
|
||||
active_model = settings.OPENROUTER_MODEL if settings.AI_PROVIDER == "openrouter" else settings.GEMINI_MODEL
|
||||
return {
|
||||
"status": "healthy",
|
||||
"ai_enabled": settings.AI_ENABLED,
|
||||
"ai_provider": settings.AI_PROVIDER,
|
||||
"ai_provider": active_provider,
|
||||
"ai_configured": ai_configured,
|
||||
"ocr_enabled": settings.OCR_ENABLED,
|
||||
"model": active_model,
|
||||
|
||||
Reference in New Issue
Block a user