diff --git a/backend/app/api/evals.py b/backend/app/api/evals.py index ca834aa8..28c6addc 100644 --- a/backend/app/api/evals.py +++ b/backend/app/api/evals.py @@ -1029,9 +1029,18 @@ async def evaluation_results(evaluation_id: str, session: AsyncSession = Depends EvalCase.id.in_({r["case_id"] for r in results if r["case_id"]})))).all()) if results else {} for r in results: r["question"] = questions.get(r["case_id"]) + r["cost"] = _result_cost(r.get("usage") or {}) return {"evaluation_id": row.id, "cleaned": row.cleaned_at is not None, "results": results} +def _result_cost(usage: dict[str, Any]) -> dict[str, Any]: + """一题的花费:助手(runner 记的 assistant 已含复核)+ 写作 + 结论裁判,和这次评测记在账上的同一份;估不出金额的调用另计 + 次数(界面写「≥」或「金额无法估算」)。加在服务端:界面不算数。""" + roles = [usage.get(k) or {} for k in ("assistant", "writer", "judge")] + return {"cost_usd": round(sum(float(r.get("cost_usd") or 0) for r in roles), 6), + "unpriced_calls": sum(int(r.get("unpriced_calls") or 0) for r in roles)} + + @router.get("/evaluations/{evaluation_id}/results/{result_id}") async def evaluation_result(evaluation_id: str, result_id: str, session: AsyncSession = Depends(get_session) ) -> dict[str, Any]: diff --git a/backend/tests/test_evals_ui_api.py b/backend/tests/test_evals_ui_api.py index 3a32da41..f80871ec 100644 --- a/backend/tests/test_evals_ui_api.py +++ b/backend/tests/test_evals_ui_api.py @@ -200,3 +200,23 @@ def test_bands_follow_the_reference_lines(): assert [evals._e1_band(x) for x in (None, 0.05, 0.1, 0.29, 0.3)] == [None, "reconcile", "normalize", "normalize", "route"] assert [evals._e3_band(x) for x in (None, 0.19, 0.2)] == [None, "not_yet", "worth"] + + +async def test_each_result_carries_its_total_cost(client, source): + """逐题结果带这一题的花费:助手(已含复核)+ 写作 + 结论裁判,估不出的另计次数——界面直接显示,不自己加。""" + suite_id = await es.make_suite(source["id"], name=f"虚构题集_{uuid.uuid4().hex[:6]}") + try: + run_id = await _evaluation(suite_id, status="succeeded", key="A", passed=1, n=1, minutes_ago=1) + async with SessionLocal() as session: + session.add(EvalResult(eval_run_id=run_id, seq=1, case_id=None, case_seq=1, case_hash="h", repeat=0, + status="ok", verdict="pass", usage={ + "assistant": {"cost_usd": 0.012, "unpriced_calls": 0}, + "review": {"cost_usd": 0.002, "unpriced_calls": 0}, + "writer": {"cost_usd": 0.03, "unpriced_calls": 1}, + "judge": {"cost_usd": 0.001, "calls": 1}})) + await session.commit() + [row] = (await client.get(f"/api/evals/evaluations/{run_id}/results")).json()["results"] + # 复核已经算在助手里(runner 记的 assistant = 建图 + 复核),不重复加 + assert row["cost"] == {"cost_usd": 0.043, "unpriced_calls": 1}, row["cost"] + finally: + await es.drop_suites() diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index e4f8696f..26c20fd9 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -19,6 +19,8 @@ import { ToolsPage } from './pages/ToolsPage' import { KnowledgePage } from './pages/KnowledgePage' import { SettingsPage } from './pages/SettingsPage' import { SchedulesPage } from './pages/schedules/SchedulesPage' +// 评测(下一轮第 4 波,评测-D8):顶级导航,搭建者以上可见 +import { EvalsPage } from './pages/evals/EvalsPage' import { NotFound } from './pages/NotFound' // 应用平台:使用面(FE-5)、搭建面的应用编辑(FE-6) import { AppsHome } from './pages/apps/AppsHome' @@ -188,6 +190,10 @@ function Shell() { } /> } /> } /> + {/* 评测:/evals 题集列表,/evals/signals、/evals/snapshots 两个页签,/evals/suites/:id 题集,/evals/runs/:id 一次评测 */} + } /> + } /> + } /> {/* 应用:固定路径(inbox)写在 /apps/:appId 前面,读的人一眼看出它不是应用 id */} } /> {/* 要在 /apps/:appId 之前:create 不是应用 id */} @@ -347,10 +353,11 @@ function Nav({ stalled }: { stalled: CatalogCheck[] }) { const live = studio.startsWith('run') || chat === 'run' const pages = usePages() - // 整条导航约 640px 高(九个导航项),窗口再矮,最底下的遥测点和署名就被切掉、够不着。 - // 矮窗口(521–660px)按高度收紧到 500px 左右(导航项 36px),≤520px 再收一档到 460px 左右(导航项 32px、 - // 图标和字之间只留 2px),而不是让导航滚动:导航一旦 overflow,挂在右侧的悬停提示和遥测浮层也会被 - // 一起裁掉。加导航项时在 600px、520px、480px 高的窗口里量一遍(check-shell 的「窗口高 …px」) + // 整条导航约 690px 高(十个导航项),窗口再矮,最底下的遥测点和署名就被切掉、够不着。 + // 矮窗口(521–660px)按高度收紧到 540px 左右(导航项 36px),≤520px 再收一档到 470px 左右(导航项 30px、 + // 图标和字之间只留 2px:17px 图标 + 2px + 11px 字正好放下),而不是让导航滚动:导航一旦 overflow,挂在右侧的 + // 悬停提示和遥测浮层也会被一起裁掉。加导航项时在 600px、520px、480px 高的窗口里量一遍(check-shell 的「窗口高 …px」)。 + // 第十项「评测」加进来时量过:≤520px 那档还是 32px 的话,480px 高的窗口里遥测点超出视口 12px,所以收到 30px return (