- 修复所有 confidence → subjective_confidence 残留(03-api, 04-agents, 05-data, 07-development) - 修复 5 张表 → 6 张表残留(06-deployment) - 同步 API schema 示例与实际模型一致 - 更新 predictions 表结构文档(新增 status/cutoff/input_hash 字段) code: 修复 API 异常处理(eval/predict)和 context_builder stats 时间过滤
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
"""评估路由。"""
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
|
|
from src.api.schemas import EvalSummaryOut, SettleRequest
|
|
from src.db.base import AsyncSession, get_db, get_db_read
|
|
from src.llm.eval import get_eval_summary, settle_prediction
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
router = APIRouter(prefix="/api/v1", tags=["eval"])
|
|
|
|
|
|
@router.post("/eval/settle")
|
|
async def settle(req: SettleRequest, db: AsyncSession = Depends(get_db)):
|
|
"""回填实际结果。"""
|
|
try:
|
|
pred = await settle_prediction(req.prediction_id, req.home_goals, req.away_goals)
|
|
return {"id": pred.id, "settled": pred.settled}
|
|
except ValueError as e:
|
|
logger.warning("settle failed: %s", e)
|
|
raise HTTPException(404, "预测记录不存在")
|
|
except Exception as e:
|
|
logger.exception("settle error")
|
|
raise HTTPException(500, "回填失败,请查看服务器日志")
|
|
|
|
|
|
@router.get("/eval/summary", response_model=EvalSummaryOut)
|
|
async def eval_summary():
|
|
"""提供商/模型准确率对比。"""
|
|
return await get_eval_summary()
|