Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/overview/Hero.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe("用量", () => {
expect(cost).toContain(t.estimated("$0.0020"));
expect(cost).toContain(t.shortUnpriced(3));
// 限定符缩小写在金额前面(单独一段),金额照常
expect(cost).toMatch(/>≥~<\/span><span class="tw-num">\$0\.032</);
expect(cost).toMatch(/>≥<\/span><span class="tw-num">\$0\.032</);
});

it("一条都没算出费用:大数写「—」,旁边写「无法计价」,不写 $0", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/overview/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ function Change({
function CostValue({ c, amount, scope }: { c: ReturnType<typeof rankCost>; amount: number; scope: string }) {
if (c.kind !== "amount") return <>—</>;
/*
指标只有一百多像素宽:「≥~」两个限定符按大数的字号写,「≥~$52.57」就放不下了。限定符
指标只有一百多像素宽:限定符按大数的字号写,「≥$52.57」就放不下了。限定符
缩小写在前面,意思不变;一千美元以上不写分,写满几位的整数
*/
return (
Expand Down
4 changes: 2 additions & 2 deletions src/overview/series.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,10 @@ describe("费用写什么", () => {
expect(rankCost(c({ cost: 500, pending: 1 }), t)).toMatchObject({ prefix: "≥", notes: [t.rankPending(1)] });
});

it("含估算:带「~」,估算的数写在悬停里;两样都有是「≥~」", () => {
it("含估算:带「~」,估算的数写在悬停里;两样都有只写「≥」", () => {
expect(rankCost(c({ cost: 500, estimated: 120 }), t)).toEqual({ kind: "amount", prefix: "~", notes: [t.estimated("$0.0001")] });
expect(rankCost(c({ cost: 500, estimated: 120, unpriced: 1 }), t)).toMatchObject({
prefix: "≥~",
prefix: "≥",
notes: [t.estimated("$0.0001"), t.rankUnpriced(1)],
});
});
Expand Down
11 changes: 2 additions & 9 deletions src/overview/series.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { densify, monthDay } from "@/format";
import { costPrefix } from "@/traffic/costCell";
import { usd, type CostBucket, type CostBucketGroup, type Dashboard, type ProviderView, type Summary } from "@/types";
import { LIVE_BUCKET_MS, LIVE_REACH_MS, liveRate, type LiveEnd, type LiveSample } from "./useLive";
import type { overviewText } from "./overview.i18n";
Expand Down Expand Up @@ -371,20 +372,12 @@ export function cacheOf(s: Pick<Summary, "input_tokens" | "cache_read_tokens" |
};
}

/**
* 金额前面的记号:缺了算不出来的请求,金额只是下限(「≥」);**估算不能冒充实测**,
* 含估算的带「~」。
*/
function costPrefix(incomplete: boolean, estimated: boolean): string {
return (incomplete ? "≥" : "") + (estimated ? "~" : "");
}

/**
* 一个费用写什么:**一个数或一个词,说明进悬停**。卡片上的费用、明细表费用那一格都按它。
*
* · 有用量、却一条都没算出费用:「无法计价」。**不写 $0** —— 那是在说它不花钱。
* · 连用量都没有:「无用量」。
* · 其余写金额。有算不出来的请求时金额只是下限,写成「≥」;含估算的带「~」。
* · 其余写金额。有算不出来的请求时金额只是下限,写成「≥」;只含估算的带「~」。
* 全都算出来了、合计是零时写 $0:不计费的上游(本地模型)就是这样,它说的是真的。
* · 实时档里价钱还没到的请求(`pending`)同样不在金额里:金额写成下限,等它们到了
* 再补上。
Expand Down
4 changes: 2 additions & 2 deletions src/traffic/costCell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ describe("会话费用那一格", () => {
expect(c.notes).toEqual([t.estimatedTip("$0.061")]);
});

it("既有估算又缺了轮次时两个记号都在", () => {
it("既有估算又缺了轮次时只写「≥」,估算了多少照样在悬停里", () => {
const c = costCell(
session({ cost_micros_estimated: 5_000, priced_turns: 9, unpriced_turns: 1 }),
t,
);
expect(c.text).toBe("≥~$0.233");
expect(c.text).toBe("≥$0.233");
expect(c.notes).toEqual([t.estimatedTip("$0.0050"), t.unpricedTurnsTip(1)]);
});

Expand Down
11 changes: 10 additions & 1 deletion src/traffic/costCell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,21 @@ export function costCell(
// **估算不能冒充实测**:合计里有估算的部分,就要带着记号
const estimated = s.cost_micros_estimated > 0;
return {
text: (outside.length > 0 ? "≥" : "") + (estimated ? "~" : "") + usd(s.cost_micros),
text: costPrefix(outside.length > 0, estimated) + usd(s.cost_micros),
muted: false,
notes: [...(estimated ? [t.estimatedTip(usd(s.cost_micros_estimated))] : []), ...outside],
};
}

/**
* 金额前面的记号,概览与会话的费用共用:缺了算不出来的请求,金额只是下限(「≥」);
* **估算不能冒充实测**,含估算的带「~」。两样都有只写「≥」:它已经说了不是准数,估算了
* 多少写在悬停里。
*/
export function costPrefix(incomplete: boolean, estimated: boolean): string {
return incomplete ? "≥" : estimated ? "~" : "";
}

/** 会话瀑布里一轮的费用:落了库的那一轮,或者表里还没落库的那一行 */
export interface TurnCost {
cost: number | null;
Expand Down
Loading