// A model's requests: the ones running now, and the ones that finished within the hour the // process remembers. import { useMemo, useState } from "react" import { Empty, Kpi, Panel } from "@/components/bits" import { Button } from "@/components/ui/button" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip" import type { FinishedRequest, Stats } from "@/lib/api" import { DASH, fAgo, fDur, fNum, fSig, fin } from "@/lib/format" import type { Scope } from "@/lib/store" import { Download } from "lucide-react" const median = (a: number[]) => { if (!a.length) return null; const s = a.slice().sort((x, y) => x - y); return s[s.length >> 1] } const STATE: Record = { prefill: "Processing prompt", decode: "Generating", waiting: "Waiting", preempted: "Paused", done: "Done" } export function Requests({ scope }: { scope: Scope }) { const s = scope.live const done = scope.finished const [shown, setShown] = useState(50) const now = scope.series.end * 1000 const speeds = done.map((r) => r.tps).filter((v): v is number => fin(v) && v > 0) const ttfts = done.map((r) => r.ttft).filter((v): v is number => fin(v)) const mean = speeds.length ? speeds.reduce((a, b) => a + b, 0) / speeds.length : null const running = (s?.requests ?? []).filter((r) => r.state !== "done") const latest = useMemo(() => done.slice().reverse(), [done, scope.version]) // eslint-disable-line react-hooks/exhaustive-deps function save() { const blob = new Blob([JSON.stringify(done, null, 1)], { type: "application/json" }) const a = document.createElement("a") a.href = URL.createObjectURL(blob) a.download = `${s?.model ?? "model"}-requests.json` a.click() setTimeout(() => URL.revokeObjectURL(a.href), 1000) } return (
0}> {running.length > 0 && ( RequestStatus Progress PromptReused WrittenSpeed Age {running.map((r) => { const reading = r.state === "prefill" const of = reading ? Math.max(1, r.prompt - r.cached) : Math.max(1, r.max) const at = reading ? Math.max(0, r.computed - r.cached) : r.output return ( {String(r.id)} {STATE[r.state] ?? r.state}
{fNum(at)} / {fNum(of)}
{fNum(r.prompt)} {r.cached ? fNum(r.cached) : DASH} {fNum(r.output)} {r.tps > 0 ? fSig(r.tps) : DASH} {fDur(r.age_s)} ) })}
)}
fin(r.tps) && r.tps! > 0 && r.ctx > 0).map((r) => ({ x: r.ctx, y: r.tps!, r }))} />
0} action={done.length > 0 && }> {done.length > 0 && ( <> RequestPrompt WrittenContext First tokenPrefill SpeedFinished {latest.slice(0, shown).map((r) => ( {r.id} {fNum(r.prompt)} {fNum(r.out)} {fNum(r.ctx)} {fin(r.ttft) ? fDur(r.ttft) : DASH} {fin(r.pf) ? fSig(r.pf) + " tok/s" : DASH} {fin(r.tps) && r.tps > 0 ? fSig(r.tps) + " tok/s" : DASH} {fAgo(r.at, now)} ))}
{latest.length > shown &&
} )}
) } const tick = (v: number) => (v >= 1000 ? fSig(v / 1000) + "k" : fSig(v)) function Scatter({ pts }: { pts: { x: number; y: number; r: FinishedRequest }[] }) { if (pts.length < 2) return Available after two finished requests const xs = pts.map((p) => p.x), ys = pts.map((p) => p.y) const x0 = Math.min(...xs), x1 = Math.max(...xs), y1 = Math.max(...ys) * 1.08 const lx = (v: number) => (x1 > x0 ? (Math.log(v) - Math.log(x0)) / (Math.log(x1) - Math.log(x0)) : 0.5) return (
{fSig(y1)}{fSig(y1 / 2)}0
{pts.map((p, i) => ( } /> {p.r.id} · {fNum(p.x)} tokens of context · {fSig(p.y)} tok/s ))}
{tick(x0)}tokens of context{tick(x1)}
) } function Histogram({ values }: { values: number[] }) { if (values.length < 2) return Available after two finished requests const edges = [0, 0.1, 0.2, 0.5, 1, 2, 5, 10, 30, Infinity] const used = edges.findIndex((e) => e > Math.max(...values)) const bins = edges.slice(0, Math.max(6, used + 1)) const counts = bins.slice(0, -1).map((lo, i) => values.filter((v) => v >= lo && v < bins[i + 1]).length) const top = Math.max(...counts, 1) const name = (i: number) => (bins[i + 1] === Infinity ? "over " + fDur(bins[i]) : "under " + fDur(bins[i + 1])) return (
{counts.map((c, i) => ( {c || ""}
} /> {c} {c === 1 ? "request" : "requests"} {name(i)}
))}
{counts.map((_, i) => {bins[i + 1] === Infinity ? "> " + fDur(bins[i]) : "< " + fDur(bins[i + 1])})}
) }