"""FastAPI application factory for the RAGAS evaluation console. The app mounts three JSON API routers and serves the single-page static frontend. It imports rag_eval only lazily (inside the task manager worker), so the server starts even when the evaluation dependencies are not yet installed. """ from __future__ import annotations from pathlib import Path from fastapi import FastAPI from fastapi.responses import FileResponse from fastapi.staticfiles import StaticFiles from webapp.api import evaluations, llm_profiles, runs, scenarios STATIC_DIR = Path(__file__).resolve().parent / "static" def create_app() -> FastAPI: """Build and configure the FastAPI application instance.""" app = FastAPI( title="Siemens RAGAS 评估控制台", description="RAGAS 评估子系统的可视化报告与评估触发控制台。", version="0.1.0", ) app.include_router(runs.router) app.include_router(scenarios.router) app.include_router(evaluations.router) app.include_router(llm_profiles.router) @app.get("/api/health", tags=["meta"]) def health() -> dict[str, str]: """Report basic liveness so the UI can confirm the server is reachable.""" return {"status": "ok"} @app.get("/", include_in_schema=False) def index() -> FileResponse: """Serve the single-page console entry document.""" return FileResponse(STATIC_DIR / "index.html") # Serve CSS/JS assets under /static while keeping API routes at /api. app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static") return app app = create_app()