Show output tokens in detail stats

This commit is contained in:
2026-04-28 13:55:08 +08:00
parent e8a66cf180
commit 94b87dcc30
3 changed files with 95 additions and 7 deletions

32
lib/detail-stats.test.ts Normal file
View File

@@ -0,0 +1,32 @@
import { describe, expect, test } from "bun:test";
import { getDetailStats } from "./detail-stats";
describe("getDetailStats", () => {
test("includes completion tokens in detail page stat cards", () => {
const stats = getDetailStats({
calls: 12,
total_tokens: 1000,
quota: 250000,
prompt_tokens: 400,
completion_tokens: 350,
cache_creation_tokens: 150,
cache_read_tokens: 100,
});
expect(stats.map((stat) => stat.key)).toEqual([
"calls",
"total_tokens",
"quota",
"prompt_tokens",
"completion_tokens",
"cache_creation_tokens",
"cache_read_tokens",
]);
expect(stats.find((stat) => stat.key === "completion_tokens")).toEqual({
key: "completion_tokens",
labelKey: "th.output",
value: 350,
format: "tokens",
});
});
});