from contextlib import asynccontextmanager from fastapi import FastAPI from fastapi.staticfiles import StaticFiles from .config import WEB_DIR from .llm_client import warm_up from .persona import load_system_prompt from .routes import chat, pages @asynccontextmanager async def lifespan(_: FastAPI): """ By the time we get here, docker-compose has already waited for llama-cpp's health check, so this hits a server that's loaded and ready — no retry loop needed. """ system_prompt = load_system_prompt() if system_prompt: await warm_up(system_prompt) yield app = FastAPI( title="Oracle Terminal", docs_url="/api/docs", openapi_url="/api/openapi.json", lifespan=lifespan, ) app.mount("/static", StaticFiles(directory=WEB_DIR / "static"), name="static") app.include_router(pages.router) app.include_router(chat.router)