from fastapi import FastAPI from fastapi.responses import HTMLResponse from pydantic import BaseModel from ragbench_eval.pipeline import RagBenchExperiment app = FastAPI(title="RAGBench RAG Evaluation API") class RunRequest(BaseModel): domain: str k: int = 3 max_examples: int = 20 split: str = "test" @app.post("/run_domain") def run_domain(req: RunRequest): exp = RagBenchExperiment( k=req.k, max_examples=req.max_examples, split=req.split, ) result = exp.run_domain(req.domain) return result @app.get("/health") def health(): return {"status": "ok"} @app.get("/") def root(): return { "message": "RAGBench RAG Evaluation API is running.", "endpoints": { "health": "/health", "docs": "/docs", "ui": "/ui", "run_domain": "/run_domain (POST)", }, } # ------------- NEW: simple frontend at /ui ----------------- @app.get("/ui", response_class=HTMLResponse) def ui(): html = """
Use this UI to call POST /run_domain and inspect the metrics
for a given domain. The backend uses the RAGBench dataset and your configured LLMs.
{}