mirror of
https://github.com/Alkatrazz24/Funk-lab.git
synced 2026-07-08 19:34:42 +02:00
Serveur : /v1/ask accepte un model optionnel (validé contre STT_ALLOWED_MODELS), nouvel endpoint GET /v1/models (défaut + alias autorisés). Pas de switch global. Client : 'stt --text' (chat texte simple sans micro/HUD), '--model hermes|claude|qwen|opus' (noms courts → alias LiteLLM), commandes /model et /models en mode texte. Le modèle choisi est envoyé au serveur à chaque requête (voix comme texte). Claude-Session: https://claude.ai/code/session_013FmcxGsyXZXogiAHQLjnZT Co-authored-by: Claude <noreply@anthropic.com>
63 lines
1.7 KiB
Python
63 lines
1.7 KiB
Python
"""STT-server — API FastAPI pour les clients STT.
|
|
|
|
Endpoints :
|
|
GET /healthz → état du service
|
|
POST /v1/ask {text} → {reply} (requête AI, orchestrée vers LiteLLM)
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import httpx
|
|
from fastapi import FastAPI, HTTPException
|
|
from pydantic import BaseModel
|
|
|
|
from stt_server import __version__
|
|
from stt_server.brain import ask as brain_ask
|
|
from stt_server.config import settings
|
|
|
|
app = FastAPI(title="STT-server", version=__version__)
|
|
|
|
|
|
class AskRequest(BaseModel):
|
|
text: str
|
|
model: str | None = None # alias LiteLLM ; défaut serveur si absent
|
|
|
|
|
|
class AskReply(BaseModel):
|
|
reply: str
|
|
model: str
|
|
|
|
|
|
@app.get("/healthz")
|
|
async def healthz() -> dict:
|
|
return {"status": "ok", "version": __version__}
|
|
|
|
|
|
@app.get("/v1/models")
|
|
async def v1_models() -> dict:
|
|
return {"default": settings.model, "available": settings.allowed_models}
|
|
|
|
|
|
@app.post("/v1/ask", response_model=AskReply)
|
|
async def v1_ask(req: AskRequest) -> AskReply:
|
|
text = req.text.strip()
|
|
if not text:
|
|
raise HTTPException(status_code=400, detail="text vide")
|
|
model = req.model or settings.model
|
|
if model not in settings.allowed_models:
|
|
raise HTTPException(
|
|
status_code=400,
|
|
detail=f"modèle '{model}' non autorisé ; dispo : {settings.allowed_models}",
|
|
)
|
|
try:
|
|
reply = await brain_ask(text, model)
|
|
except httpx.HTTPError as e:
|
|
raise HTTPException(status_code=502, detail=f"upstream LiteLLM : {e}") from e
|
|
return AskReply(reply=reply, model=model)
|
|
|
|
|
|
def run() -> None:
|
|
"""Entrypoint `stt-server` (dev local). En prod : uvicorn via le conteneur."""
|
|
import uvicorn
|
|
|
|
uvicorn.run(app, host="0.0.0.0", port=8000) # noqa: S104 — service interne au cluster
|