Spaces:
Sleeping
Sleeping
perf: startup menu preload + /ping keepalive endpoint
Browse files1234561 unmodified line89101112131418 unmodified lines333435363738"""Bell backend β voice ordering API for BYG Brewski (Bolna tool endpoints +frontend endpoints). Runs on HuggingFace Spaces (port 7860) or locally."""from fastapi import FastAPIfrom fastapi.middleware.cors import CORSMiddleware1 unmodified linefrom routes import calls, copilot, menu, orders, reservations, tokens_route, webhooksfrom store import get_storeapp = FastAPI(title="Bell β BYG Brewski Voice Ordering API", version="1.0.0")app.add_middleware(CORSMiddleware,18 unmodified linesreturn {"service": "bell-backend", "restaurant": "BYG Brewski", "docs": "/docs"}@app.get("/api/health")async def health():"""Read-only health check β never seeds or mutates state."""123456781 unmodified line10111213141516171819202122232425262718 unmodified lines46474849505152535455565758"""Bell backend β voice ordering API for BYG Brewski (Bolna tool endpoints +frontend endpoints). Runs on HuggingFace Spaces (port 7860) or locally."""from contextlib import asynccontextmanagerfrom fastapi import FastAPIfrom fastapi.middleware.cors import CORSMiddleware1 unmodified linefrom routes import calls, copilot, menu, orders, reservations, tokens_route, webhooksfrom store import get_store@asynccontextmanagerasync def lifespan(app: FastAPI):# Pre-warm the store on startup so the first tool call is fast.try:get_store().get_menu()except Exception:passyieldapp = FastAPI(title="Bell β BYG Brewski Voice Ordering API", version="1.0.0", lifespan=lifespan)app.add_middleware(CORSMiddleware,18 unmodified linesreturn {"service": "bell-backend", "restaurant": "BYG Brewski", "docs": "/docs"}@app.get("/ping")async def ping():"""Ultra-lightweight keepalive β frontend pings every 90s to prevent HF cold starts."""return {"ok": True}@app.get("/health")@app.get("/api/health")async def health():"""Read-only health check β never seeds or mutates state."""
main.py+21-1