perf(startup): lokale Modelle beim Start vorladen (Warm-up)
Lifespan-Hintergrundtask laedt profilabhaengig piper-Stimme + faster-whisper-Modell vor (nur was die aktive Konfiguration nutzt; Cloud-Profile = No-op). Server ist sofort verfuegbar; der erste Nutzer zahlt nicht mehr den Kaltstart. Messung: erster Turn direkt nach Start first_audio 1,62 s (statt ~4,5 s mit Kaltstart). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
7ca69e1049
commit
111ecd8edf
3 changed files with 84 additions and 1 deletions
15
app/main.py
15
app/main.py
|
|
@ -1,9 +1,12 @@
|
|||
import asyncio
|
||||
import time
|
||||
from contextlib import asynccontextmanager
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from app.core.warmup import warmup_local_models
|
||||
from app.metrics import metrics
|
||||
from app.api.health import router as health_router
|
||||
from app.api.chat import router as chat_router
|
||||
|
|
@ -17,7 +20,17 @@ from app.api.me import router as me_router
|
|||
from app.api.metrics import router as metrics_router
|
||||
from app.api.ws import router as ws_router
|
||||
|
||||
app = FastAPI(title="Voice Assistant Gateway")
|
||||
@asynccontextmanager
|
||||
async def _lifespan(app: FastAPI):
|
||||
# Lokale Modelle im Hintergrund vorladen -> Server ist sofort verfuegbar,
|
||||
# der erste Nutzer zahlt nicht den Kaltstart.
|
||||
task = asyncio.create_task(warmup_local_models())
|
||||
yield
|
||||
if not task.done():
|
||||
task.cancel()
|
||||
|
||||
|
||||
app = FastAPI(title="Voice Assistant Gateway", lifespan=_lifespan)
|
||||
|
||||
|
||||
@app.middleware("http")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue