Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ba9b830d50 | |||
| 32291c8768 | |||
| 9dedb48d9a | |||
| a392656d44 | |||
| 9285ebe012 |
@@ -38,6 +38,26 @@ const fmtCost = (c: number | null) => (c == null ? '-' : `¥${c.toFixed(4)}`);
|
|||||||
const fmtTok = (inTok: number | null, outTok: number | null) =>
|
const fmtTok = (inTok: number | null, outTok: number | null) =>
|
||||||
inTok == null && outTok == null ? '-' : `${inTok ?? 0}/${outTok ?? 0}`;
|
inTok == null && outTok == null ? '-' : `${inTok ?? 0}/${outTok ?? 0}`;
|
||||||
|
|
||||||
|
// LLM 价格快照:每模型单价(元/每百万 token)+ 本次分桶 token + 后端按当时价冻结的该模型成本
|
||||||
|
// cost_yuan(=null 即该模型待补价)。旧记录快照只有单价、无 token/成本字段(input_tokens 缺失)→
|
||||||
|
// 退回只显示单价那行,不硬凑 0/0。忽略 mode/_source 等元字段。
|
||||||
|
function llmPriceRows(snapshot: Record<string, unknown> | null): string[] {
|
||||||
|
const prices = snapshot?.prices;
|
||||||
|
if (!prices || typeof prices !== 'object') return [];
|
||||||
|
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 就缩进展开,否则原样。
|
// LLM message content 常是 json.dumps 的卡片列表;能 parse 成 JSON 就缩进展开,否则原样。
|
||||||
function pretty(s: string | null): string {
|
function pretty(s: string | null): string {
|
||||||
if (!s) return '';
|
if (!s) return '';
|
||||||
@@ -357,8 +377,8 @@ export default function ComparisonRecordsPage() {
|
|||||||
)}
|
)}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
{detail.llm_price_snapshot ? (
|
{detail.llm_price_snapshot ? (
|
||||||
<Descriptions.Item label="价格快照" span={2}>
|
<Descriptions.Item label="LLM 单价/成本快照" span={2}>
|
||||||
<pre style={preStyle}>{JSON.stringify(detail.llm_price_snapshot, null, 2)}</pre>
|
{llmPriceRows(detail.llm_price_snapshot).map((r) => <div key={r}>{r}</div>)}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
) : null}
|
) : null}
|
||||||
<Descriptions.Item label="源平台">{detail.source_platform_name || '-'}({cents(detail.source_price_cents)})</Descriptions.Item>
|
<Descriptions.Item label="源平台">{detail.source_platform_name || '-'}({cents(detail.source_price_cents)})</Descriptions.Item>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ interface ConfigItem {
|
|||||||
key: string;
|
key: string;
|
||||||
label: string;
|
label: string;
|
||||||
group: string;
|
group: string;
|
||||||
type: string; // int / int_list / dict_str_int / bool
|
type: string; // int / int_list / dict_str_int / bool / json
|
||||||
help: string | null;
|
help: string | null;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
default: any;
|
default: any;
|
||||||
@@ -24,7 +24,7 @@ interface ConfigItem {
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
function toEdit(item: ConfigItem): any {
|
function toEdit(item: ConfigItem): any {
|
||||||
if (item.type === 'int_list') return (item.value as number[]).join(', ');
|
if (item.type === 'int_list') return (item.value as number[]).join(', ');
|
||||||
if (item.type === 'dict_str_int') return JSON.stringify(item.value);
|
if (item.type === 'dict_str_int' || item.type === 'json') return JSON.stringify(item.value);
|
||||||
return item.value;
|
return item.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ function fromEdit(type: string, raw: any): any {
|
|||||||
.split(',')
|
.split(',')
|
||||||
.map((s) => parseInt(s.trim(), 10));
|
.map((s) => parseInt(s.trim(), 10));
|
||||||
}
|
}
|
||||||
if (type === 'dict_str_int') return JSON.parse(raw);
|
if (type === 'dict_str_int' || type === 'json') return JSON.parse(raw);
|
||||||
return raw;
|
return raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user