From ba9b830d5007d515430fa1f08d80ddff327c2428 Mon Sep 17 00:00:00 2001 From: guke Date: Mon, 20 Jul 2026 09:50:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A8=A1=E5=9E=8B=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E5=B1=95=E7=A4=BA=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(main)/comparison-records/page.tsx | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/app/(main)/comparison-records/page.tsx b/src/app/(main)/comparison-records/page.tsx index 6d57be6..a6d2678 100644 --- a/src/app/(main)/comparison-records/page.tsx +++ b/src/app/(main)/comparison-records/page.tsx @@ -38,13 +38,24 @@ const fmtCost = (c: number | null) => (c == null ? '-' : `¥${c.toFixed(4)}`); const fmtTok = (inTok: number | null, outTok: number | null) => inTok == null && outTok == null ? '-' : `${inTok ?? 0}/${outTok ?? 0}`; -// LLM 价格快照只展示 prices 里各模型的单价(元/每百万 token),忽略 mode/_source 等元字段。 +// LLM 价格快照:每模型单价(元/每百万 token)+ 本次分桶 token + 后端按当时价冻结的该模型成本 +// cost_yuan(=null 即该模型待补价)。旧记录快照只有单价、无 token/成本字段(input_tokens 缺失)→ +// 退回只显示单价那行,不硬凑 0/0。忽略 mode/_source 等元字段。 function llmPriceRows(snapshot: Record | null): string[] { const prices = snapshot?.prices; if (!prices || typeof prices !== 'object') return []; - return Object.entries(prices as Record).map( - ([model, p]) => `${model} 输入 ${p?.input_per_1m ?? '-'}元/每百万tokens,输出${p?.output_per_1m ?? '-'}元/每百万tokens`, - ); + return Object.entries( + prices as Record< + string, + { input_per_1m?: number; output_per_1m?: number; input_tokens?: number; output_tokens?: number; cost_yuan?: number | null } + >, + ).map(([model, p]) => { + const unit = `输入 ${p?.input_per_1m ?? '-'}元/每百万tokens,输出${p?.output_per_1m ?? '-'}元/每百万tokens`; + if (p?.input_tokens == null) return `${model} ${unit}`; // 旧记录:无 token/成本字段 + const tok = `${p.input_tokens}/${p.output_tokens ?? 0} tokens`; + const cost = p.cost_yuan == null ? '待补价' : `¥${p.cost_yuan}`; + return `${model} ${unit},本次 ${tok},成本 ${cost}`; + }); } // LLM message content 常是 json.dumps 的卡片列表;能 parse 成 JSON 就缩进展开,否则原样。 @@ -366,7 +377,7 @@ export default function ComparisonRecordsPage() { )} {detail.llm_price_snapshot ? ( - + {llmPriceRows(detail.llm_price_snapshot).map((r) =>
{r}
)}
) : null}