Release / release (push) Successful in 3m17s
A deterministic quality eval as a run type next to BetterBench: tool calling (12 requests), coding (8 Python functions checked by unit tests in a locked-down sandbox container) and long-context retrieval (needle at 3 depths in 3 lengths up to the context). Versioned eval set in src/evals/v1, score stored per run, shown on the run page, in compare views, the benchmark list and sweep tables (optional eval per variant); API kind "eval", quality in run/sweep/compare answers; skill updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
400 lines
15 KiB
TypeScript
400 lines
15 KiB
TypeScript
"use client";
|
||
|
||
import {
|
||
DownloadIcon,
|
||
ExternalLinkIcon,
|
||
RotateCcwIcon,
|
||
SquareIcon,
|
||
Trash2Icon,
|
||
TriangleAlertIcon,
|
||
} from "lucide-react";
|
||
import Link from "next/link";
|
||
import { useRouter } from "next/navigation";
|
||
import { useEffect, useState } from "react";
|
||
import { toast } from "sonner";
|
||
import { BenchmarkStateBadge } from "@/components/benchmark-state";
|
||
import { CopyButton } from "@/components/copy-button";
|
||
import { LiveLog } from "@/components/live-log";
|
||
import { LocalTime } from "@/components/local-time";
|
||
import {
|
||
AlertDialog,
|
||
AlertDialogAction,
|
||
AlertDialogCancel,
|
||
AlertDialogContent,
|
||
AlertDialogDescription,
|
||
AlertDialogFooter,
|
||
AlertDialogHeader,
|
||
AlertDialogTitle,
|
||
AlertDialogTrigger,
|
||
} from "@/components/ui/alert-dialog";
|
||
import { Button, buttonVariants } from "@/components/ui/button";
|
||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||
import { Input } from "@/components/ui/input";
|
||
import { reportSummary, weightsLabel } from "@/lib/benchmark-report";
|
||
import { CONFIG_ROWS, describeSettings } from "@/lib/benchmark-view";
|
||
import type { ListRow } from "../benchmark-list";
|
||
import { AgentApprovalBar } from "@/components/approval-bar";
|
||
import { RequestedByBadge } from "@/components/requested-by-badge";
|
||
import { RunMetaCard } from "@/components/run-meta";
|
||
import { cancelBenchmark, deleteBenchmark, describeBenchmark, renameBenchmark } from "../actions";
|
||
import { AbReport } from "./ab-report";
|
||
import { QualityReport } from "./quality-report";
|
||
import { BenchmarkReport } from "./benchmark-report";
|
||
import { PublishCard } from "./publish-card";
|
||
|
||
function duration(a: string | null, b: string | null, now: number) {
|
||
if (!a) return null;
|
||
const s = Math.max(
|
||
0,
|
||
((b ? new Date(b).getTime() : now) - new Date(a).getTime()) / 1000,
|
||
);
|
||
const h = Math.floor(s / 3600);
|
||
const m = Math.floor((s % 3600) / 60);
|
||
return h
|
||
? `${h} h ${m} min`
|
||
: m
|
||
? `${m} min ${Math.round(s % 60)} s`
|
||
: `${Math.round(s)} s`;
|
||
}
|
||
|
||
export function BenchmarkDetail({ initial }: { initial: ListRow }) {
|
||
const router = useRouter();
|
||
const [r, setR] = useState(initial);
|
||
const [now, setNow] = useState(() => Date.now());
|
||
const [label, setLabel] = useState(initial.label ?? "");
|
||
const [description, setDescription] = useState(initial.description ?? "");
|
||
const active = r.state === "pending_approval" || r.state === "queued" || r.state === "running";
|
||
|
||
useEffect(() => {
|
||
if (!active) return;
|
||
const t = setInterval(async () => {
|
||
setNow(Date.now());
|
||
const res = await fetch(`/api/benchmarks/${r.id}`, {
|
||
cache: "no-store",
|
||
}).catch(() => null);
|
||
if (res?.ok) setR(await res.json());
|
||
}, 2_000);
|
||
return () => clearInterval(t);
|
||
}, [active, r.id]);
|
||
|
||
async function again() {
|
||
if (!r.deploymentId) return;
|
||
const res = await fetch("/api/benchmarks", {
|
||
method: "POST",
|
||
headers: { "Content-Type": "application/json" },
|
||
body: JSON.stringify({
|
||
deploymentId: r.deploymentId,
|
||
deploymentBId: r.kind === "ab" ? r.deploymentBId : null,
|
||
kind: r.kind,
|
||
label: r.label,
|
||
description: r.description,
|
||
...r.settings,
|
||
}),
|
||
});
|
||
const json = await res.json().catch(() => ({}));
|
||
if (!res.ok)
|
||
return toast.error(
|
||
json.error?.message ?? `Could not start (${res.status})`,
|
||
);
|
||
router.push(`/benchmarks/${json.id}`);
|
||
}
|
||
|
||
const s = r.snapshot;
|
||
const sum = r.summary;
|
||
const took = duration(r.startedAt, r.finishedAt, now);
|
||
|
||
return (
|
||
<div className="flex flex-col gap-4">
|
||
<Card>
|
||
<CardContent className="flex flex-wrap items-start justify-between gap-4">
|
||
<div className="flex min-w-0 flex-col gap-1">
|
||
<div className="flex flex-wrap items-center gap-2">
|
||
<h1 className="text-xl font-semibold">
|
||
{r.label ??
|
||
(r.kind === "ab"
|
||
? `${s.deploymentName} vs ${r.snapshotB?.deploymentName}`
|
||
: s.deploymentName)}
|
||
</h1>
|
||
{r.kind === "ab" && (
|
||
<span className="rounded-md border px-1.5 text-xs text-muted-foreground">
|
||
A/B
|
||
</span>
|
||
)}
|
||
<BenchmarkStateBadge
|
||
state={r.state}
|
||
cancelling={!!r.cancelRequestedAt}
|
||
/>
|
||
<RequestedByBadge name={r.requestedBy} />
|
||
</div>
|
||
<p className="text-sm text-muted-foreground">
|
||
{r.deploymentId ? (
|
||
<Link
|
||
href={`/deployments/${r.deploymentId}`}
|
||
className="hover:underline"
|
||
>
|
||
{s.deploymentName}
|
||
</Link>
|
||
) : (
|
||
`${s.deploymentName} (deleted)`
|
||
)}{" "}
|
||
·{" "}
|
||
{r.modelId ? (
|
||
<Link href={`/${s.repoId}`} className="hover:underline">
|
||
{s.repoId}
|
||
</Link>
|
||
) : (
|
||
s.repoId
|
||
)}{" "}
|
||
· {s.runtimeName}
|
||
{r.kind === "ab" && r.snapshotB && (
|
||
<>
|
||
{" "}
|
||
· B:{" "}
|
||
{r.deploymentBId ? (
|
||
<Link
|
||
href={`/deployments/${r.deploymentBId}`}
|
||
className="hover:underline"
|
||
>
|
||
{r.snapshotB.deploymentName}
|
||
</Link>
|
||
) : (
|
||
r.snapshotB.deploymentName
|
||
)}
|
||
</>
|
||
)}
|
||
{r.sweepId && (
|
||
<>
|
||
{" "}
|
||
·{" "}
|
||
<Link
|
||
href={`/benchmarks/sweeps/${r.sweepId}`}
|
||
className="hover:underline"
|
||
>
|
||
part of a sweep
|
||
</Link>
|
||
</>
|
||
)}
|
||
</p>
|
||
<p className="text-xs text-muted-foreground">
|
||
{r.kind === "eval" ? "Kaname" : "BetterBench"} ·{" "}
|
||
{r.kind === "ab"
|
||
? `paired A/B, target ±${r.settings.mdePct ?? 1}%, up to ${r.settings.maxPairs ?? 200} pairs`
|
||
: describeSettings(r.settings)}{" "}
|
||
· created <LocalTime value={r.createdAt} />
|
||
{took &&
|
||
` · ${r.state === "running" ? "running for" : "took"} ${took}`}
|
||
</p>
|
||
</div>
|
||
<div className="flex flex-wrap items-center gap-2">
|
||
{r.hasReport && (
|
||
<a
|
||
href={`/api/benchmarks/${r.id}/report`}
|
||
target="_blank"
|
||
rel="noreferrer"
|
||
className={buttonVariants({ variant: "outline" })}
|
||
>
|
||
<ExternalLinkIcon />
|
||
Full report
|
||
</a>
|
||
)}
|
||
{r.state === "completed" && (
|
||
<a
|
||
href={`/api/benchmarks/${r.id}/results`}
|
||
className={buttonVariants({ variant: "outline" })}
|
||
>
|
||
<DownloadIcon />
|
||
{r.kind === "ab" ? "ab.json" : "results.json"}
|
||
</a>
|
||
)}
|
||
{active ? (
|
||
<Button
|
||
variant="outline"
|
||
disabled={!!r.cancelRequestedAt}
|
||
onClick={async () =>
|
||
(await cancelBenchmark(r.id)) && router.refresh()
|
||
}
|
||
>
|
||
<SquareIcon />
|
||
Cancel
|
||
</Button>
|
||
) : (
|
||
r.deploymentId &&
|
||
!r.sweepId && (
|
||
<Button
|
||
variant="outline"
|
||
onClick={again}
|
||
title="Queue a new run with the same settings (the deployment must be running)"
|
||
>
|
||
<RotateCcwIcon />
|
||
Run again
|
||
</Button>
|
||
)
|
||
)}
|
||
<AlertDialog>
|
||
<AlertDialogTrigger
|
||
render={
|
||
<Button
|
||
variant="outline"
|
||
disabled={r.state === "running"}
|
||
className="text-destructive hover:bg-destructive/10 hover:text-destructive"
|
||
/>
|
||
}
|
||
>
|
||
<Trash2Icon />
|
||
Delete
|
||
</AlertDialogTrigger>
|
||
<AlertDialogContent>
|
||
<AlertDialogHeader>
|
||
<AlertDialogTitle>Delete this benchmark?</AlertDialogTitle>
|
||
<AlertDialogDescription>
|
||
Its numbers, log, results.json and HTML report are removed.
|
||
</AlertDialogDescription>
|
||
</AlertDialogHeader>
|
||
<AlertDialogFooter>
|
||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||
<AlertDialogAction
|
||
variant="destructive"
|
||
onClick={async () => {
|
||
if (await deleteBenchmark(r.id)) {
|
||
router.push("/benchmarks");
|
||
router.refresh();
|
||
}
|
||
}}
|
||
>
|
||
Delete
|
||
</AlertDialogAction>
|
||
</AlertDialogFooter>
|
||
</AlertDialogContent>
|
||
</AlertDialog>
|
||
</div>
|
||
</CardContent>
|
||
</Card>
|
||
|
||
{r.state === "pending_approval" && (
|
||
<AgentApprovalBar
|
||
requestedBy={r.requestedBy}
|
||
what={`run ${r.kind === "ab" ? "an A/B" : r.kind === "eval" ? "the quality eval" : "a benchmark"} on ${s.deploymentName} (${describeSettings(r.settings)}${r.timeLimitS ? `, at most ${Math.round(r.timeLimitS / 60)} min` : ""})`}
|
||
base={`/api/benchmarks/${r.id}`}
|
||
/>
|
||
)}
|
||
{r.error && (
|
||
<div className="flex gap-3 rounded-xl border border-destructive/30 bg-destructive/10 px-4 py-3 text-sm">
|
||
<TriangleAlertIcon className="mt-0.5 size-4 shrink-0 text-destructive" />
|
||
<pre className="min-w-0 flex-1 font-sans break-words whitespace-pre-wrap">
|
||
{r.error}
|
||
</pre>
|
||
</div>
|
||
)}
|
||
{r.state === "queued" && (
|
||
<p className="text-sm text-muted-foreground">
|
||
Waiting: benchmarks run one at a time.
|
||
</p>
|
||
)}
|
||
{r.state === "running" && r.phase && (
|
||
<p className="text-sm text-muted-foreground">Now: {r.phase}</p>
|
||
)}
|
||
|
||
<div className="grid items-start gap-4 lg:grid-cols-[minmax(0,1fr)_340px]">
|
||
<div className="flex min-w-0 flex-col gap-4">
|
||
{r.kind === "ab" ? <AbReport run={r} /> : r.kind === "eval" ? <QualityReport quality={r.quality} running={active} /> : <BenchmarkReport run={r} />}
|
||
<LiveLog
|
||
url={`/api/benchmarks/${r.id}/logs`}
|
||
title="BetterBench output"
|
||
live={active}
|
||
/>
|
||
</div>
|
||
|
||
<aside className="flex flex-col gap-4">
|
||
{r.kind === "run" && r.state === "completed" && r.summary && (
|
||
<PublishCard
|
||
runId={r.id}
|
||
defaultTitle={r.label ?? `${s.repoId} ${weightsLabel(s)}`}
|
||
defaultSummary={reportSummary(r)}
|
||
/>
|
||
)}
|
||
<Card size="sm">
|
||
<CardHeader>
|
||
<CardTitle>Label</CardTitle>
|
||
</CardHeader>
|
||
<CardContent>
|
||
<Input
|
||
value={label}
|
||
maxLength={120}
|
||
placeholder="e.g. q8_0 KV cache"
|
||
onChange={(e) => setLabel(e.target.value)}
|
||
onBlur={async () =>
|
||
label !== (r.label ?? "") &&
|
||
(await renameBenchmark(r.id, label || null)) &&
|
||
setR({ ...r, label: label.trim() || null })
|
||
}
|
||
onKeyDown={(e) =>
|
||
e.key === "Enter" && (e.target as HTMLInputElement).blur()
|
||
}
|
||
/>
|
||
</CardContent>
|
||
</Card>
|
||
<Card size="sm">
|
||
<CardHeader>
|
||
<CardTitle>Description</CardTitle>
|
||
</CardHeader>
|
||
<CardContent className="flex flex-col gap-1.5">
|
||
<textarea
|
||
value={description}
|
||
maxLength={4000}
|
||
rows={3}
|
||
placeholder="What this run tries out, e.g. q8_0 KV cache to fit 64k context"
|
||
className="w-full rounded-md border bg-transparent px-2.5 py-1.5 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring/50"
|
||
onChange={(e) => setDescription(e.target.value)}
|
||
onBlur={async () =>
|
||
description !== (r.description ?? "") &&
|
||
(await describeBenchmark(r.id, description || null)) &&
|
||
setR({ ...r, description: description.trim() || null })
|
||
}
|
||
/>
|
||
<p className="text-[11px] text-muted-foreground">
|
||
Passed to BetterBench (when set before the run starts) and to the launch80 preview, together with the system summary.
|
||
</p>
|
||
</CardContent>
|
||
</Card>
|
||
<RunMetaCard meta={r.meta} metaB={r.metaB} system={r.system} />
|
||
{r.kind !== "ab" && (
|
||
<Card size="sm">
|
||
<CardHeader>
|
||
<CardTitle>Settings measured</CardTitle>
|
||
</CardHeader>
|
||
<CardContent className="flex flex-col gap-3">
|
||
<dl className="grid grid-cols-[max-content_1fr] gap-x-4 gap-y-1 text-xs">
|
||
{CONFIG_ROWS.map((row) => {
|
||
const v = row.value(s);
|
||
return v == null ? null : (
|
||
<div key={row.key} className="contents">
|
||
<dt className="text-muted-foreground">{row.label}</dt>
|
||
<dd className="min-w-0 font-mono break-all">{v}</dd>
|
||
</div>
|
||
);
|
||
})}
|
||
</dl>
|
||
<div className="flex flex-col gap-1">
|
||
<div className="flex items-center justify-between text-xs text-muted-foreground">
|
||
Command
|
||
<CopyButton value={s.command} label="Copy command" />
|
||
</div>
|
||
<pre className="rounded-md bg-muted/60 px-2 py-1.5 font-mono text-[11px] break-all whitespace-pre-wrap">
|
||
{s.command}
|
||
</pre>
|
||
</div>
|
||
{sum && (
|
||
<p className="text-[11px] text-muted-foreground">
|
||
BetterBench {sum.betterbenchVersion} · corpus v
|
||
{sum.corpusVersion} · phases: {sum.phases.join(", ") || "–"}
|
||
</p>
|
||
)}
|
||
</CardContent>
|
||
</Card>
|
||
)}
|
||
</aside>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|