Add RAGAS evaluation web console (FastAPI + vanilla JS)
- webapp/: FastAPI backend with runs/scenarios/evaluations API routers; services for run_reader, report_builder, scenario_scanner, task_manager (lazy ragas import — server boots even without ragas); Pydantic models - webapp/static/: single-page console (layout A: left-nav + main area); report detail with metric cards, Chart.js distribution histogram, grouping table, lowest-score sample review; trigger evaluation + log polling - webmain.py: uvicorn entry point (alongside existing main.py CLI) - start.bat: Windows one-click launcher with env checks and auto-browser open - rag_eval/datasets/: implement missing loader + normalizer modules (load_dataset_records, normalize_records) required by evaluator - scripts/seed_sample_run.py: generate realistic demo run artifacts - .gitignore: exclude datasets/ data files but keep rag_eval/datasets/ source Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
This commit is contained in:
49
webapp/server.py
Normal file
49
webapp/server.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""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, 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.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()
|
||||
Reference in New Issue
Block a user