"use client"; import { useEffect, useMemo, useState } from "react"; import toast from "react-hot-toast"; import { Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts"; type LeaderboardRow = { model: string; runs: number; avgScore: number; refusalRate: number; // 0..1 }; export default function LeaderboardPage() { const [rows, setRows] = useState(null); const [dbEnabled, setDbEnabled] = useState(null); const [error, setError] = useState(null); useEffect(() => { let cancelled = false; (async () => { try { const res = await fetch("/api/leaderboard", { cache: "no-store" }); const json = (await res.json()) as { rows: LeaderboardRow[]; dbEnabled?: boolean }; if (cancelled) return; setRows(json.rows); setDbEnabled(Boolean(json.dbEnabled)); } catch (e) { if (cancelled) return; const message = e instanceof Error ? e.message : "Failed to load leaderboard."; setError(message); toast.error(message); } })(); return () => { cancelled = true; }; }, []); const sortedRows = useMemo(() => { if (!rows) return []; return [...rows].sort((a, b) => b.avgScore - a.avgScore); // Default sort by score }, [rows]); const topModel = sortedRows[0]; const chartData = useMemo(() => { if (!rows) return []; // Show top 10 models by refusal rate for the chart return rows .slice() .sort((a, b) => b.refusalRate - a.refusalRate) .slice(0, 10) .map((r) => ({ model: r.model, refusalPct: Math.round(r.refusalRate * 100) })); }, [rows]); return (
{/* Header */}

Global Leaderboard

Aggregated anonymous benchmark results from the community. Comparisons are based on self-reported local runs.

{error && (
Error: {error}
)} {dbEnabled === false && (
⚠️ Leaderboard storage not configured. Set DATABASE_URL to enable global text sharing.
)} {/* Stats Cards */} {topModel && (
Top Model
{topModel.model}
Score: {topModel.avgScore}
Total Runs
{rows?.reduce((acc, r) => acc + r.runs, 0) ?? 0}
Across {rows?.length ?? 0} models
Avg Refusal Rate
{rows && rows.length > 0 ? Math.round(rows.reduce((acc, r) => acc + r.refusalRate, 0) / rows.length * 100) : 0}%
Global Average
)}
{/* Main Table */}

Model Rankings

{(sortedRows ?? []).map((r, i) => ( ))} {(!sortedRows || sortedRows.length === 0) && ( )}
Rank Model Runs Avg Score Refusal %
#{i + 1} {r.model} {r.runs} {r.avgScore} 0.5 ? "text-red-400" : "text-gray-400"}> {Math.round(r.refusalRate * 100)}%
No data available yet. Be the first to run a benchmark!
{/* Chart Column */}

Refusal Rate (Top 10)

); }