"use client"; import { useState } from "react"; import type { BenchmarkPlan, BenchmarkResult } from "@/lib/modelfit"; import { fetchBenchmarkPreview, runBenchmark } from "@/lib/modelfit"; const TASKS = ["latency", "throughput", "rag", "context_stress", "abstention"]; const QUANTS = ["q2_k", "q3_k", "q4_0", "q4_k", "q5_k", "q8", "fp16"]; export function BenchmarkLab({ defaultModelId = "", }: { defaultModelId?: string; }) { const [modelId, setModelId] = useState(defaultModelId); const [quantization, setQuantization] = useState("q4_k"); const [task, setTask] = useState("latency"); const [numExamples, setNumExamples] = useState(10); const [plan, setPlan] = useState(null); const [result, setResult] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [phase, setPhase] = useState<"idle" | "preview" | "running" | "done">("idle"); async function preview() { if (!modelId.trim()) return; setLoading(true); setError(null); setResult(null); try { const p = await fetchBenchmarkPreview(modelId.trim(), quantization, task, numExamples); setPlan(p); setPhase("preview"); } catch (e) { setError(String(e)); } finally { setLoading(false); } } async function run() { if (!modelId.trim()) return; setLoading(true); setError(null); setPhase("running"); try { const r = await runBenchmark(modelId.trim(), quantization, task, numExamples); setResult(r); setPlan(null); setPhase("done"); } catch (e) { setError(String(e)); setPhase("preview"); } finally { setLoading(false); } } return (
{/* Config */}
setModelId(e.target.value)} />
setNumExamples(Number(e.target.value))} />
{phase === "preview" && plan && ( )}
{error &&

Error: {error}

} {/* Preview plan */} {plan && phase === "preview" && (

DRY RUN — No benchmark has run yet

{plan.note}

Model {plan.model_id} Quantization {plan.quantization} Task {plan.task} Examples {plan.num_examples} Est. duration {plan.estimated_duration_min} min Requires Ollama {plan.requires_ollama ? "Yes" : "No"} Auto-download Never
{plan.warnings.map((w, i) => (

⚠ {w}

))}

Sample prompts

{plan.sample_prompts.map((p, i) => (

"{p}"

))}
)} {/* Running */} {phase === "running" && (
Running benchmark against {modelId}…

This may take several minutes. No model will be downloaded.

)} {/* Result */} {result && phase === "done" && ( )}
); } function BenchmarkResultCard({ result }: { result: BenchmarkResult }) { const statusColor = result.status === "completed" ? "text-emerald-400" : result.status === "failed" ? "text-red-400" : "text-zinc-400"; return (
run/{result.run_id} {result.status}
{result.error && (

Error: {result.error}

)} {result.status === "completed" && (
Avg tok/s {result.avg_tok_per_sec != null ? `${result.avg_tok_per_sec} (measured)` : "not measured"} p50 latency {result.p50_latency_ms != null ? `${result.p50_latency_ms} ms` : "—"} p95 latency {result.p95_latency_ms != null ? `${result.p95_latency_ms} ms` : "—"} TTFT {result.time_to_first_token_ms != null ? `${result.time_to_first_token_ms} ms` : "—"} Peak memory {result.peak_memory_gb != null ? `${result.peak_memory_gb} GB` : "—"} Examples {result.completed_examples}/{result.num_examples}
)} {result.warnings.map((w, i) => (

⚠ {w}

))}
); }