Spaces:
Sleeping
Sleeping
File size: 1,941 Bytes
a812c01 0e1b580 a812c01 0b14ebe a812c01 0e1b580 a812c01 0b14ebe a812c01 0e1b580 a812c01 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | """Bell backend — voice ordering API for BYG Brewski (Bolna tool endpoints +
frontend endpoints). Runs on HuggingFace Spaces (port 7860) or locally."""
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import config
from routes import calls, copilot, menu, orders, reservations, tokens_route, webhooks
from store import get_store
@asynccontextmanager
async def lifespan(app: FastAPI):
# Pre-warm the store on startup so the first tool call is fast.
try:
get_store().get_menu()
except Exception:
pass
yield
app = FastAPI(title="Bell — BYG Brewski Voice Ordering API", version="1.0.0", lifespan=lifespan)
app.add_middleware(
CORSMiddleware,
allow_origins=config.CORS_ORIGINS,
allow_origin_regex=r"https://.*\.vercel\.app",
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(menu.router)
app.include_router(orders.router)
app.include_router(calls.router)
app.include_router(webhooks.router)
app.include_router(copilot.router)
app.include_router(reservations.router)
app.include_router(tokens_route.router)
@app.get("/")
async def root():
return {"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."""
try:
store_health = get_store().health()
return {"status": "ok", **store_health, "bolna_configured": bool(config.BOLNA_AGENT_ID)}
except Exception as exc:
return {"status": "degraded", "error": str(exc)}
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=7860, reload=True)
|