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
75 changes: 60 additions & 15 deletions src/overview/ModelRanking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { useNav } from "@/nav";
import { compact } from "@/format";
import { usd } from "@/types";
import { useText } from "@/i18n";
import type { Metric, RankRow } from "./series";
import { LinkRow, MarkSpace, Meter, ModelMark } from "./parts";
import { rankCost, type Metric, type RankRow } from "./series";
import { LinkRow, LinkText, MarkSpace, Meter, ModelMark } from "./parts";
import { overviewText } from "./overview.i18n";

const fmtTokens = (n: number) => compact(Math.round(n));
Expand Down Expand Up @@ -66,19 +66,9 @@ export function ModelRanking({
<AnimatedNumber value={r.tokens} format={fmtTokens} scope={scope} />
</span>
</Tip>
<span className={cn("w-16 shrink-0 text-right", tokensMode ? "text-muted-foreground" : "font-medium")}>
{/*
**用了 token 却没有费用,不写「$0」。**那可能是未定价(费用没算进来),也
可能是不计费(本地模型)—— 分组的格子里没有「无法计价」的条数,分不出是哪
一种,而「$0」只在后一种情况下是真的。
*/}
{r.cost === 0 && r.tokens > 0 ? (
<Tip text={t.noCost}>
<span className="tw-num text-muted-foreground">—</span>
</Tip>
) : (
<AnimatedNumber value={r.cost} format={usd} scope={scope} />
)}
{/* 80px:「≥~$1234.56」要 79 */}
<span className={cn("w-20 shrink-0 text-right", tokensMode ? "text-muted-foreground" : "font-medium")}>
<Cost r={r} scope={scope} />
</span>
<span className="w-12 shrink-0 text-right tw-label text-muted-foreground">
<AnimatedNumber value={r.requests} format={(n) => t.times(Math.round(n))} scope={scope} />
Expand All @@ -88,3 +78,58 @@ export function ModelRanking({
</div>
);
}

/**
* 一行的费用。写什么见 `rankCost`;有说明的写在悬停里。
*
* · 金额有说明时带虚线下划线,和会话、请求行里有说明的金额同一个记号。
* · 「无法计价」是琥珀色:它要人去补一个价,和上面费用大数下的「N 条无法计价」同色。
* 「无用量」补不了什么,淡一档。两个词都不跟着费用口径加粗 —— 它们不是金额。
*
* **有无法计价的请求时,这一格自己可以点**:落到流量页这个模型里没算出费用的那一批
* —— 看到它之后要做的就是去补价,而补给谁要从那一批里看。合并的「其他」不是一个
* 模型,只说不点。
*/
function Cost({ r, scope }: { r: RankRow; scope: string }) {
const t = useText(overviewText);
const nav = useNav();
const c = rankCost(r, t);
if (c.kind === "amount" && c.notes.length === 0)
return <AnimatedNumber value={r.cost} format={usd} scope={scope} />;
const shown =
c.kind === "unpriced" ? (
t.unpricedCell
) : c.kind === "noUsage" ? (
t.noUsageCell
) : (
<AnimatedNumber value={r.cost} format={(n) => c.prefix + usd(n)} scope={scope} />
);
const look =
c.kind === "amount"
? "underline decoration-dotted underline-offset-2"
: c.kind === "unpriced"
? "font-normal text-warning"
: "font-normal text-muted-foreground";
const tip = (
<div className="space-y-1">
{c.notes.map((l) => (
<p key={l}>{l}</p>
))}
</div>
);
return (
<Tip text={tip}>
{r.unpriced > 0 && !r.merged ? (
<LinkText
className={cn(look, "hover:decoration-solid")}
onOpen={() => nav.open("requests", { grouped: false, filter: { model: r.name, unpricedOnly: true } })}
>
{shown}
<span className="sr-only">{t.viewUnpriced}</span>
</LinkText>
) : (
<span className={look}>{shown}</span>
)}
</Tip>
);
}
26 changes: 23 additions & 3 deletions src/overview/overview.i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export const overviewText = messages(
costRate: (amount: string) => `${amount}/小时`,
/** 悬停提示抬头下面那一句:这一格有几次请求 */
tipRequests: (requests: number, failed: number) => `${requests} 次请求${failed ? `,${failed} 次失败` : ""}`,
/** 那一句后面接着的几项(费用口径下的「3 条无法计价」)之间的分隔 */
listSep: ",",
tipNone: "无请求",
waiting: "等待请求",
noRequests: "所选区间内无请求记录",
Expand All @@ -81,8 +83,15 @@ export const overviewText = messages(
// 模型排行
models: "模型",
times: (n: number) => `${n} 次`,
/** 用了 token 却没有费用的那一格(「—」)的悬停说明 */
noCost: "无费用记录:模型未定价或不计费",
/** 排行费用那一格(和费用口径下悬停的合计):有用量,却一条都没算出费用 */
unpricedCell: "无法计价",
/** 同上:连用量都没有 */
noUsageCell: "无用量",
/** 费用那一格悬停里的句子:金额之外的请求。含估算的那句和费用大数的限定语共用 `estimated` */
rankUnpriced: (n: number) => `${n} 条请求无法计价:模型未定价,费用未计入`,
rankNoUsage: (n: number) => `${n} 条请求没有用量数据,费用未计入`,
/** 可以点的「无法计价」,读屏读出来的后半句 */
viewUnpriced: "在流量中查看无法计价的请求",
moreNotListed: (n: number) => `另有 ${n} 项未列出`,
/** 可以点的一行,读屏读出来的后半句 */
viewInTraffic: "在流量中查看",
Expand Down Expand Up @@ -199,6 +208,7 @@ export const overviewText = messages(
costRate: (amount: string) => `${amount}/hour`,
tipRequests: (requests: number, failed: number) =>
`${requests === 1 ? "1 request" : `${requests} requests`}${failed ? `, ${failed} failed` : ""}`,
listSep: ", ",
tipNone: "No requests",
waiting: "Waiting for requests",
noRequests: "No requests recorded in the selected range",
Expand All @@ -209,7 +219,17 @@ export const overviewText = messages(

models: "Models",
times: (n: number) => `${n}×`,
noCost: "No cost recorded: the model is unpriced or not billed",
unpricedCell: "Unpriced",
noUsageCell: "No usage",
rankUnpriced: (n: number) =>
n === 1
? "1 request unpriced: the model has no price, so its cost is not included"
: `${n} requests unpriced: the model has no price, so their cost is not included`,
rankNoUsage: (n: number) =>
n === 1
? "1 request has no usage data, so its cost is not included"
: `${n} requests have no usage data, so their cost is not included`,
viewUnpriced: "View unpriced requests in Traffic",
moreNotListed: (n: number) => `${n} more not listed`,
viewInTraffic: "View in Traffic",

Expand Down
28 changes: 23 additions & 5 deletions src/overview/parts.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { KeyboardEvent, ReactNode } from "react";
import type { ComponentProps, KeyboardEvent, ReactNode } from "react";
import { ChevronRightIcon } from "lucide-react";
import { cn } from "@/lib/utils";
import { Badge } from "@/ui/badge";
Expand Down Expand Up @@ -84,22 +84,40 @@ export function LinkRow({

/**
* 一段可以点的字(「6 次失败」「3 条无法计价」)。悬停出下划线,键盘同样能打开。
*
* **别的属性原样落到这个 span 上**:套在 `Tip` 里时,悬停提示的触发器把指针、焦点的
* 处理和 ref 交给它,吞掉的话提示永远不出来。
*
* 点击和按键只打开它自己,**不再往上冒泡**:它放在一整行都能点的排行里时(排行里
* 「无法计价」那一格),那一行不该跟着再打开一次。
*/
export function LinkText({
onOpen,
className,
children,
}: {
onClick,
onKeyDown,
...rest
}: Omit<ComponentProps<"span">, "role" | "tabIndex"> & {
onOpen: () => void;
className?: string;
children: ReactNode;
}) {
const activate = onActivate(onOpen);
return (
<span
{...rest}
role="link"
tabIndex={0}
onClick={onOpen}
onKeyDown={onActivate(onOpen)}
onClick={(e) => {
onClick?.(e);
e.stopPropagation();
onOpen();
}}
onKeyDown={(e) => {
onKeyDown?.(e);
if (e.key === "Enter" || e.key === " ") e.stopPropagation();
activate(e);
}}
className={cn(
"cursor-pointer rounded-sm underline-offset-2 outline-none transition-colors duration-(--motion-fast) hover:underline focus-visible:underline focus-visible:ring-2 focus-visible:ring-ring/40",
className,
Expand Down
Loading
Loading