feat(token-tracking): add Token usage panel to the report detail page
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -185,6 +185,10 @@
|
|||||||
<div class="advice-body" id="advice-body"></div>
|
<div class="advice-body" id="advice-body"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- ⑥ Token 用量(按模型分组,不换算金额) -->
|
||||||
|
<div class="section-label">⑥ Token 用量</div>
|
||||||
|
<div class="panel" id="token-usage-wrap"></div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ const Report = {
|
|||||||
Report.renderGroupings(detail.report);
|
Report.renderGroupings(detail.report);
|
||||||
Report.renderLowest(detail.report);
|
Report.renderLowest(detail.report);
|
||||||
Report.renderAdvice(detail.summary, detail.report);
|
Report.renderAdvice(detail.summary, detail.report);
|
||||||
|
Report.renderTokenUsage(detail.report);
|
||||||
content.style.opacity = "1";
|
content.style.opacity = "1";
|
||||||
|
|
||||||
// 同步下拉选中项
|
// 同步下拉选中项
|
||||||
@@ -254,6 +255,26 @@ const Report = {
|
|||||||
tableEl.innerHTML = `<table class="group-table">${head}${body}</table>`;
|
tableEl.innerHTML = `<table class="group-table">${head}${body}</table>`;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 渲染"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 = '<p class="muted tiny">暂无 token 用量数据。</p>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let head = "<tr><th>模型</th><th>input_tokens</th><th>output_tokens</th><th>调用次数</th></tr>";
|
||||||
|
let body = "";
|
||||||
|
models.forEach((model) => {
|
||||||
|
const u = usage[model] || {};
|
||||||
|
body += `<tr><td>${App.escape(model)}</td><td>${u.input_tokens ?? 0}</td>` +
|
||||||
|
`<td>${u.output_tokens ?? 0}</td><td>${u.calls ?? 0}</td></tr>`;
|
||||||
|
});
|
||||||
|
wrap.innerHTML = `<table class="group-table">${head}${body}</table>`;
|
||||||
|
},
|
||||||
|
|
||||||
// ④ 最低分样本逐条复核表(点击展开)。
|
// ④ 最低分样本逐条复核表(点击展开)。
|
||||||
renderLowest(report) { const wrap = document.getElementById("lowest-table");
|
renderLowest(report) { const wrap = document.getElementById("lowest-table");
|
||||||
const samples = report.lowest_samples || [];
|
const samples = report.lowest_samples || [];
|
||||||
|
|||||||
Reference in New Issue
Block a user