Spaces:
Running
Running
File size: 11,742 Bytes
36d93d2 d3a614e 36d93d2 d3a614e 36d93d2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | /* ==========================================================================
ToolUse.1 — shared client
Loads results (live results.json, else embedded snapshot), renders the
leaderboard, and drives the motion layer: reveal-on-scroll, count-up,
score bars, sortable columns.
========================================================================== */
"use strict";
/* Gate motion behind a class so the no-JS view stays fully visible. */
document.documentElement.classList.add("js");
/* Inlined snapshot so pages render when opened straight from disk
(file:// blocks fetch). A served results.json overrides it. */
const EMBEDDED_RESULTS = {
benchmark: "ToolUse.1",
version: "1.0.0",
updated: "2026-10-17",
corpus: { cases: 114, call_cases: 78, no_call_cases: 36, tools: 9, protocols: 3 },
rows: [
{
model: "oracle",
link: "",
protocol: "all",
score: 1.0,
score_ci95: [0.9889, 1.0],
correct_call: 1.0,
abstention: 1.0,
spurious_call_rate: 0.0,
n_cases: 342,
notes: "reads the expectations out of the corpus — grader reference",
self_check: true,
by_protocol: { json: 1.0, xml: 1.0, plain: 1.0 },
},
{
model: "HardcoreAI/Nova-1.1-0.8B",
link: "https://huggingface.co/HardcoreAI/Nova-1.1-0.8B",
protocol: "all",
score: 0.6404,
score_ci95: [0.5882, 0.6894],
correct_call: 0.5855,
abstention: 0.7593,
spurious_call_rate: 0.1667,
n_cases: 342,
notes: "greedy · thinking off · batch 8 · English-only · fine-tuned",
self_check: false,
by_protocol: { json: 0.6754, xml: 0.6316, plain: 0.614 },
},
{
model: "Qwen/Qwen3.5-0.8B",
link: "https://huggingface.co/Qwen/Qwen3.5-0.8B",
protocol: "all",
score: 0.5936,
score_ci95: [0.5408, 0.6443],
correct_call: 0.4829,
abstention: 0.8333,
spurious_call_rate: 0.0648,
n_cases: 342,
notes: "greedy · thinking off · batch 8 · English-only · base model",
self_check: false,
by_protocol: { json: 0.6754, xml: 0.6754, plain: 0.4298 },
},
],
};
const pct = (v) => (typeof v === "number" ? (v * 100).toFixed(1) + "%" : "—");
const ci = (lo, hi) => (lo == null || hi == null ? "—" : `${(lo * 100).toFixed(1)}% – ${(hi * 100).toFixed(1)}%`);
const prefersReduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
/* ------------------------------------------------------------- motion */
function revealOnScroll(root = document) {
const nodes = root.querySelectorAll(".reveal");
if (prefersReduced || !("IntersectionObserver" in window)) {
nodes.forEach((n) => n.classList.add("in"));
return;
}
const io = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("in");
io.unobserve(entry.target);
}
});
},
{ rootMargin: "0px 0px -8% 0px", threshold: 0.08 },
);
nodes.forEach((n) => io.observe(n));
}
function countUp(el) {
const target = parseFloat(el.dataset.count);
const suffix = el.dataset.suffix || "";
if (prefersReduced || Number.isNaN(target)) { el.textContent = `${target}${suffix}`; return; }
const start = performance.now();
const dur = 900;
const step = (now) => {
const t = Math.min(1, (now - start) / dur);
const eased = 1 - Math.pow(1 - t, 3);
el.textContent = `${Math.round(target * eased)}${suffix}`;
if (t < 1) requestAnimationFrame(step);
else el.textContent = `${target}${suffix}`;
};
requestAnimationFrame(step);
}
/* ------------------------------------------------------------- rendering */
function scoreCell(value) {
const wrap = document.createElement("div");
wrap.className = "score-cell";
const bar = document.createElement("div");
bar.className = "bar";
const fill = document.createElement("i");
fill.dataset.w = Math.max(0, Math.min(1, value || 0));
bar.append(fill);
const val = document.createElement("span");
val.className = "score-value";
val.textContent = pct(value);
wrap.append(bar, val);
return wrap;
}
function spuriousCell(value) {
const cell = document.createElement("td");
cell.className = "num";
if (typeof value !== "number") { cell.textContent = "—"; return cell; }
cell.textContent = pct(value);
cell.classList.add(value >= 0.3 ? "spurious-high" : value >= 0.1 ? "spurious-mid" : "");
return cell;
}
function protoMini(byProtocol) {
const wrap = document.createElement("div");
wrap.className = "proto-mini";
["json", "xml", "plain"].forEach((key) => {
const box = document.createElement("div");
const label = document.createElement("span");
label.className = "pl";
label.textContent = key;
const bar = document.createElement("div");
bar.className = "pb";
const fill = document.createElement("i");
fill.dataset.w = Math.max(0, Math.min(1, byProtocol?.[key] ?? 0));
bar.append(fill);
const val = document.createElement("span");
val.className = "pv";
val.textContent = pct(byProtocol?.[key]);
box.append(label, bar, val);
wrap.append(box);
});
return wrap;
}
function rowNode(row, index, opts = {}) {
const { withProtocol = false, withNotes = false } = opts;
const tr = document.createElement("tr");
tr.dataset.score = row.score ?? 0;
tr.dataset.correct_call = row.correct_call ?? 0;
tr.dataset.abstention = row.abstention ?? 0;
tr.dataset.spurious_call_rate = row.spurious_call_rate ?? 0;
tr.dataset.n_cases = row.n_cases ?? 0;
const rank = document.createElement("td");
rank.className = "col-rank";
const badge = document.createElement("span");
badge.className = `rank-badge${index < 3 ? ` rank-${index + 1}` : ""}`;
badge.textContent = index + 1;
rank.append(badge);
tr.append(rank);
const model = document.createElement("td");
model.className = "col-model";
if (row.link) {
const a = document.createElement("a");
a.className = "model-link model-name";
a.href = row.link;
a.target = "_blank";
a.rel = "noopener";
a.textContent = row.model;
model.append(a);
} else {
const s = document.createElement("span");
s.className = "model-name";
s.textContent = row.model;
model.append(s);
}
const sub = [row.protocol === "all" ? "all protocols" : `protocol: ${row.protocol}`, row.notes].filter(Boolean).join(" · ");
if (sub) {
const s = document.createElement("span");
s.className = "model-sub";
s.textContent = sub;
model.append(s);
}
tr.append(model);
const score = document.createElement("td");
score.className = "num";
score.append(scoreCell(row.score));
const c = document.createElement("span");
c.className = "ci";
c.textContent = Array.isArray(row.score_ci95) ? ci(row.score_ci95[0], row.score_ci95[1]) : "";
score.append(c);
tr.append(score);
tr.append(Object.assign(document.createElement("td"), { className: "num", textContent: pct(row.correct_call) }));
tr.append(Object.assign(document.createElement("td"), { className: "num", textContent: pct(row.abstention) }));
tr.append(spuriousCell(row.spurious_call_rate));
tr.append(Object.assign(document.createElement("td"), { className: "num", textContent: row.n_cases ?? "—" }));
if (withProtocol) {
const proto = document.createElement("td");
proto.append(protoMini(row.by_protocol));
tr.append(proto);
}
if (withNotes) {
const notes = document.createElement("td");
notes.className = "col-notes";
if (row.self_check) {
const tag = document.createElement("span");
tag.className = "tag";
tag.textContent = "grader self-check";
notes.append(tag);
} else if (row.notes) {
const span = document.createElement("span");
span.className = "ci";
span.textContent = row.notes;
notes.append(span);
}
tr.append(notes);
}
return tr;
}
function renderBoard(data, host) {
const tbody = host.querySelector("[data-board-body]");
const stamp = host.querySelector("[data-board-stamp]");
const emptyEl = host.querySelector("[data-board-empty]");
const rows = [...(data.rows || [])].sort(
(a, b) => (b.score ?? 0) - (a.score ?? 0) || (a.spurious_call_rate ?? 1) - (b.spurious_call_rate ?? 1),
);
const hasProtocolCol = !!host.querySelector("[data-col-protocol]");
const hasNotesCol = !!host.querySelector("[data-col-notes]");
tbody.replaceChildren(...rows.map((row, i) => rowNode(row, i, { withProtocol: hasProtocolCol, withNotes: hasNotesCol })));
if (stamp) {
stamp.textContent = [
`${rows.length} entr${rows.length === 1 ? "y" : "ies"}`,
data.version ? `v${data.version}` : "",
data.updated ? `updated ${data.updated}` : "",
].filter(Boolean).join(" · ");
}
if (emptyEl) emptyEl.hidden = rows.length > 0;
requestAnimationFrame(() => {
tbody.querySelectorAll("tr").forEach((tr, i) => {
setTimeout(() => tr.classList.add("in"), prefersReduced ? 0 : 40 * i);
});
tbody.querySelectorAll(".bar > i, .pb > i").forEach((fill) => {
fill.style.width = `${Math.max(0, Math.min(1, parseFloat(fill.dataset.w) || 0)) * 100}%`;
});
});
}
/* ------------------------------------------------------------- sorting */
function wireSorting(host) {
const headers = host.querySelectorAll("th[data-sort]");
headers.forEach((th) => {
th.classList.add("sortable");
if (!th.querySelector(".arrow")) th.insertAdjacentHTML("beforeend", ' <span class="arrow">↑↓</span>');
th.addEventListener("click", () => {
const key = th.dataset.sort;
const dir = th.getAttribute("aria-sort") === "descending" ? "ascending" : "descending";
headers.forEach((h) => h.removeAttribute("aria-sort"));
th.setAttribute("aria-sort", dir);
const tbody = host.querySelector("[data-board-body]");
const glyph = th.querySelector(".arrow");
if (glyph) glyph.textContent = dir === "descending" ? " ↓" : " ↑";
const rows = [...tbody.querySelectorAll("tr")];
rows.sort((a, b) => {
const av = parseFloat(a.dataset[key]) || 0;
const bv = parseFloat(b.dataset[key]) || 0;
return dir === "descending" ? bv - av : av - bv;
});
tbody.replaceChildren(...rows);
});
});
}
/* ------------------------------------------------------------- bootstrap */
async function loadResults() {
try {
const res = await fetch("results.json", { cache: "no-store" });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return await res.json();
} catch {
return EMBEDDED_RESULTS;
}
}
function applyMetricCards(data) {
const best = [...(data.rows || [])]
.filter((r) => !r.self_check && typeof r.score === "number")
.sort((a, b) => (b.score ?? 0) - (a.score ?? 0))[0];
if (!best) return;
const map = { overall: best.score, call: best.correct_call, abstain: best.abstention };
document.querySelectorAll("[data-metric]").forEach((el) => {
const v = map[el.dataset.metric];
if (typeof v === "number") el.textContent = pct(v);
});
const leader = document.querySelector("[data-leader]");
if (leader) leader.textContent = best.model;
}
document.addEventListener("DOMContentLoaded", async () => {
document.querySelectorAll("[data-count]").forEach(countUp);
revealOnScroll();
const boards = document.querySelectorAll("[data-board]");
if (!boards.length) return;
const data = await loadResults();
boards.forEach((host) => {
renderBoard(data, host);
wireSorting(host);
});
applyMetricCards(data);
const year = document.getElementById("year");
if (year) year.textContent = new Date().getFullYear();
});
|