From 6bad007cd9128d5168a5e8ff56697ae109d9bf2c Mon Sep 17 00:00:00 2001 From: wangwei Date: Thu, 2 Jul 2026 15:40:37 +0800 Subject: [PATCH] feat(token-tracking): add Token usage panel to the report detail page Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- webapp/static/index.html | 4 ++++ webapp/static/js/report.js | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/webapp/static/index.html b/webapp/static/index.html index 02c1fa4..b48180b 100644 --- a/webapp/static/index.html +++ b/webapp/static/index.html @@ -185,6 +185,10 @@
+ + +
⑥ Token 用量
+
diff --git a/webapp/static/js/report.js b/webapp/static/js/report.js index 6a2a2ed..49b80a9 100644 --- a/webapp/static/js/report.js +++ b/webapp/static/js/report.js @@ -32,6 +32,7 @@ const Report = { Report.renderGroupings(detail.report); Report.renderLowest(detail.report); Report.renderAdvice(detail.summary, detail.report); + Report.renderTokenUsage(detail.report); content.style.opacity = "1"; // 同步下拉选中项 @@ -254,6 +255,26 @@ const Report = { tableEl.innerHTML = `${head}${body}
`; }, + // 渲染"Token 用量"面板:按模型分组的 input/output/调用次数表格。 + renderTokenUsage(report) { + const wrap = document.getElementById("token-usage-wrap"); + if (!wrap) return; + const usage = report.token_usage || {}; + const models = Object.keys(usage).sort(); + if (models.length === 0) { + wrap.innerHTML = '

暂无 token 用量数据。

'; + return; + } + let head = "模型input_tokensoutput_tokens调用次数"; + let body = ""; + models.forEach((model) => { + const u = usage[model] || {}; + body += `${App.escape(model)}${u.input_tokens ?? 0}` + + `${u.output_tokens ?? 0}${u.calls ?? 0}`; + }); + wrap.innerHTML = `${head}${body}
`; + }, + // ④ 最低分样本逐条复核表(点击展开)。 renderLowest(report) { const wrap = document.getElementById("lowest-table"); const samples = report.lowest_samples || [];