Each API module now logs: - evaluations: trigger (scenario path, task_id), status polls, list - runs: list (count), detail (run_id, metrics, sample counts) - scenarios: list (total, valid, error counts) - pipeline: submit (docs_path, models, max_docs), status polls, list - llm_profiles: CRUD ops (name, model, id), probe/test (model, ok, latency), apply (patched fields) - score: already had per-request logging Global middleware (webapp.access logger): - Every API request: METHOD path -> status (latency_ms) at INFO - Static file requests demoted to DEBUG to reduce noise Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
44 lines
1.6 KiB
Python
44 lines
1.6 KiB
Python
"""Routes for listing evaluation runs and fetching a single run's report."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
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"])
|
|
logger = logging.getLogger("webapp.api.runs")
|
|
|
|
|
|
@router.get("")
|
|
def get_runs() -> dict[str, list]:
|
|
"""Return summaries for every discoverable evaluation run."""
|
|
summaries = run_reader.list_run_summaries()
|
|
logger.info("[get_runs] found %d runs", len(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."""
|
|
logger.info("[get_run_detail] run_id=%s", run_id)
|
|
run_dir = run_reader.find_run_dir(run_id)
|
|
if run_dir is None:
|
|
logger.warning("[get_run_detail] not found run_id=%s", run_id)
|
|
raise HTTPException(status_code=404, detail=f"未找到运行: {run_id}")
|
|
|
|
summary = run_reader.build_run_summary(run_dir)
|
|
if summary is None:
|
|
logger.warning("[get_run_detail] missing metadata run_id=%s", run_id)
|
|
raise HTTPException(status_code=404, detail=f"运行元数据缺失: {run_id}")
|
|
|
|
report = report_builder.build_report(run_dir, summary.metrics)
|
|
logger.info(
|
|
"[get_run_detail] ok run_id=%s metrics=%s valid=%d invalid=%d",
|
|
run_id, summary.metrics, summary.valid_samples, summary.invalid_samples,
|
|
)
|
|
return RunDetail(summary=summary, report=report)
|