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/CacheSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function CacheSection({ d, scope, scoped }: { d: Dashboard; scope: string
key={key}
className={cn("h-7 gap-2.5", rowMotion(presence))}
hint={t.viewInTraffic}
onOpen={() => nav.open("requests", { grouped: false, filter: { q: r.name } })}
onOpen={() => nav.open("requests", { grouped: false, filter: { model: r.name } })}
>
<ModelMark name={r.name} />
<span className="min-w-0 flex-1 truncate" title={r.name}>
Expand Down
2 changes: 1 addition & 1 deletion src/overview/LatencySection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function LatencySection({
max={max}
scope={scope}
mark={(name) => <ModelMark name={name} />}
onOpen={(name) => nav.open("requests", { grouped: false, filter: { q: name } })}
onOpen={(name) => nav.open("requests", { grouped: false, filter: { model: name } })}
/>
{upstreams && (
<Spreads
Expand Down
2 changes: 1 addition & 1 deletion src/overview/ModelRanking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function ModelRanking({
key={key}
className={rowMotion(presence)}
hint={r.merged ? undefined : t.viewInTraffic}
onOpen={r.merged ? undefined : () => nav.open("requests", { grouped: false, filter: { q: r.name } })}
onOpen={r.merged ? undefined : () => nav.open("requests", { grouped: false, filter: { model: r.name } })}
onPoint={(on) => onFocus(on ? r.name : null)}
>
{r.merged ? <MarkSpace /> : <ModelMark name={r.name} />}
Expand Down
22 changes: 22 additions & 0 deletions src/requestTable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,28 @@ describe("过滤下拉的取值", () => {
});
});

describe("按模型筛", () => {
const row = (id: number, model?: string): RequestRow => ({
id,
client: "c",
provider: "p",
path: "/v1/messages",
atMs: id,
state: "done",
model,
});

/** 概览上 gpt-5.5 那一行不含 gpt-5.5-codex,点进来看到的也不能含 */
it("整个名字相等才算,不是子串", () => {
const rows = [row(1, "gpt-5.5"), row(2, "gpt-5.5-codex"), row(3)];
expect(filterRows(rows, { ...EMPTY_FILTER, model: "gpt-5.5" }).map((r) => r.id)).toEqual([1]);
});

it("出现过的模型进下拉,没报模型的不算", () => {
expect(facets([row(1, "b"), row(2, "a"), row(3)]).models).toEqual(["a", "b"]);
});
});

describe("只看无法计价的", () => {
const row = (x: Partial<RequestRow>): RequestRow => ({
id: 1,
Expand Down
16 changes: 15 additions & 1 deletion src/requestTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export interface Filter {
client: string;
/** 限定某个上游。空串 = 不限 */
provider: string;
/**
* 限定某个模型,**整个名字相等**才算。空串 = 不限
*
* 从概览点一个模型进来走的是它,不是 `q`:自由文本是子串匹配,点 gpt-5.5
* 会把 gpt-5.5-codex 一起筛出来,而概览上那一行的数字不含它。
*/
model: string;
/**
* 只看没算出金额的。
*
Expand All @@ -35,6 +42,7 @@ export const EMPTY_FILTER: Filter = {
failedOnly: false,
client: "",
provider: "",
model: "",
unpricedOnly: false,
};

Expand All @@ -44,7 +52,8 @@ export function hasAnyFilter(f: Filter): boolean {
f.failedOnly ||
f.unpricedOnly ||
f.client !== "" ||
f.provider !== ""
f.provider !== "" ||
f.model !== ""
);
}

Expand Down Expand Up @@ -120,6 +129,7 @@ export function filterRows(rows: RequestRow[], f: Filter): RequestRow[] {
return false;
if (f.client && r.client !== f.client) return false;
if (f.provider && r.provider !== f.provider) return false;
if (f.model && r.model !== f.model) return false;
if (!q) return true;
// 路径、密钥、应用、来源、上游、模型、错误信息都算 —— 排查时记得住的
// 往往是错误里的那半句话,而不是哪个字段装着它。
Expand All @@ -139,15 +149,19 @@ export function filterRows(rows: RequestRow[], f: Filter): RequestRow[] {
export function facets(rows: RequestRow[]): {
clients: string[];
providers: string[];
models: string[];
} {
const c = new Set<string>();
const p = new Set<string>();
const m = new Set<string>();
for (const r of rows) {
if (r.client) c.add(r.client);
if (r.provider) p.add(r.provider);
if (r.model) m.add(r.model);
}
return {
clients: [...c].sort(),
providers: [...p].sort(),
models: [...m].sort(),
};
}
2 changes: 2 additions & 0 deletions src/traffic/Traffic.i18n.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const trafficText = messages(
unpricedOnly: "仅显示无法计价",
allClients: "全部密钥",
allUpstreams: "全部上游",
allModels: "全部模型",
shownOf: (shown: number, total: number) => `${shown} / ${total} 条`,
clear: "清空",

Expand Down Expand Up @@ -145,6 +146,7 @@ export const trafficText = messages(
unpricedOnly: "Unpriced only",
allClients: "All keys",
allUpstreams: "All upstreams",
allModels: "All models",
shownOf: (shown: number, total: number) => `${shown} / ${count(total, "request", "requests")}`,
clear: "Clear",

Expand Down
19 changes: 19 additions & 0 deletions src/traffic/TrafficPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,25 @@ export default function TrafficPage({
))}
</NativeSelect>
)}
{/*
模型只在筛着的时候出现(从概览点一个模型进来):平时按模型找用搜索框就够,
再常驻一个下拉,默认窗口宽度下过滤条就折成两行。筛着的模型可能还没出现在
已读到的行里 —— 照样列出来,筛子不能藏着。
*/}
{filter.model !== "" && (
<NativeSelect
size="sm"
value={filter.model}
onChange={(e) => setFilter((f) => ({ ...f, model: e.target.value }))}
>
<NativeSelectOption value="">{t.allModels}</NativeSelectOption>
{(facet.models.includes(filter.model) ? facet.models : [filter.model, ...facet.models]).map((m) => (
<NativeSelectOption key={m} value={m}>
{m}
</NativeSelectOption>
))}
</NativeSelect>
)}
{/*
筛掉了多少要说出来:只写「12 条」不写「共 340 条」,会以为总共就这么多。
没筛的时候不写 —— 页头已经说了一共几条。
Expand Down
Loading