33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
|
|
"""Routes for listing evaluation runs and fetching a single run's report."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from fastapi import APIRouter, HTTPException
|
||
|
|
|
||
|
|
from webapp.models import RunDetail
|
||
|
|
from webapp.services import report_builder, run_reader
|
||
|
|
|
||
|
|
router = APIRouter(prefix="/api/runs", tags=["runs"])
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("")
|
||
|
|
def get_runs() -> dict[str, list]:
|
||
|
|
"""Return summaries for every discoverable evaluation run."""
|
||
|
|
summaries = run_reader.list_run_summaries()
|
||
|
|
return {"runs": [summary.model_dump() for summary in summaries]}
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("/{run_id}")
|
||
|
|
def get_run_detail(run_id: str) -> RunDetail:
|
||
|
|
"""Return the full summary and aggregated report for one run."""
|
||
|
|
run_dir = run_reader.find_run_dir(run_id)
|
||
|
|
if run_dir is None:
|
||
|
|
raise HTTPException(status_code=404, detail=f"未找到运行: {run_id}")
|
||
|
|
|
||
|
|
summary = run_reader.build_run_summary(run_dir)
|
||
|
|
if summary is None:
|
||
|
|
raise HTTPException(status_code=404, detail=f"运行元数据缺失: {run_id}")
|
||
|
|
|
||
|
|
report = report_builder.build_report(run_dir, summary.metrics)
|
||
|
|
return RunDetail(summary=summary, report=report)
|