Add admin panel, WebSocket support, and API versioning
Introduce an admin portal (React + Nginx), WebSocket routing, and API versioning middleware with `/api/v1/` prefix deprecation. Add master API key authentication, new Prometheus metrics for AI token consumption and active WebSockets, and extend S3 config with a public endpoint URL. Update test paths and fixtures to align with the new routing structure.
This commit is contained in:
+14
-1
@@ -14,6 +14,7 @@ from app.services.scraper import fetch_page_content
|
||||
from app.services.ai_vision import summarize_url, draft_task
|
||||
from app.config import settings
|
||||
from app.middleware import limiter
|
||||
from app.metrics import hub_ai_tokens_consumed
|
||||
|
||||
|
||||
router = APIRouter(prefix="/ai", tags=["Intelligence Artificielle"])
|
||||
@@ -62,7 +63,7 @@ async def summarize_link(
|
||||
language=body.language,
|
||||
)
|
||||
|
||||
return SummarizeResponse(
|
||||
resp = SummarizeResponse(
|
||||
url=body.url,
|
||||
title=page.get("title"),
|
||||
summary=result["summary"],
|
||||
@@ -70,6 +71,13 @@ async def summarize_link(
|
||||
model=result["model"],
|
||||
)
|
||||
|
||||
# Metrics
|
||||
if result.get("prompt_tokens") or result.get("output_tokens"):
|
||||
total = (result.get("prompt_tokens") or 0) + (result.get("output_tokens") or 0)
|
||||
hub_ai_tokens_consumed.labels(client_id=client.id, model=result["model"]).inc(total)
|
||||
|
||||
return resp
|
||||
|
||||
|
||||
@router.post(
|
||||
"/draft-task",
|
||||
@@ -99,4 +107,9 @@ async def generate_task(
|
||||
if not result.get("title"):
|
||||
raise HTTPException(status_code=500, detail="Échec de la génération de la tâche")
|
||||
|
||||
# Metrics
|
||||
if result.get("prompt_tokens") or result.get("output_tokens"):
|
||||
total = (result.get("prompt_tokens") or 0) + (result.get("output_tokens") or 0)
|
||||
hub_ai_tokens_consumed.labels(client_id=client.id, model=result.get("model", "unknown")).inc(total)
|
||||
|
||||
return DraftTaskResponse(**result)
|
||||
|
||||
Reference in New Issue
Block a user