505 lines
16 KiB
Svelte
505 lines
16 KiB
Svelte
<script lang="ts">
|
||
import { onMount, untrack } from "svelte";
|
||
import {
|
||
api,
|
||
errorLabel,
|
||
fmtDuration,
|
||
fmtPct,
|
||
fmtTps,
|
||
isInfrastructure,
|
||
groupLabel,
|
||
pctColor,
|
||
type BatchInfo,
|
||
type Ranking,
|
||
type RunRow,
|
||
type StepRow,
|
||
} from "$lib/api";
|
||
|
||
let { selected = $bindable(null) }: { selected: number | null } = $props();
|
||
|
||
let batches = $state<BatchInfo[]>([]);
|
||
let ranking = $state<Ranking | null>(null);
|
||
let rows = $state<RunRow[]>([]);
|
||
let error = $state("");
|
||
let loading = $state(false);
|
||
let detail = $state<{ run: RunRow; steps: StepRow[] } | null>(null);
|
||
let showRuns = $state(false);
|
||
|
||
async function loadBatches() {
|
||
try {
|
||
batches = await api.batches();
|
||
if (selected === null && batches.length > 0) selected = batches[0].id;
|
||
} catch (e) {
|
||
error = String(e);
|
||
}
|
||
}
|
||
|
||
async function loadBatch(id: number | null) {
|
||
ranking = null;
|
||
rows = [];
|
||
detail = null;
|
||
if (id === null) return;
|
||
loading = true;
|
||
error = "";
|
||
try {
|
||
[ranking, rows] = await Promise.all([api.ranking(id), api.results(id)]);
|
||
} catch (e) {
|
||
error = String(e);
|
||
} finally {
|
||
loading = false;
|
||
}
|
||
}
|
||
|
||
onMount(loadBatches);
|
||
|
||
// Beim Wechsel des Batches neu laden. Neue Batches erscheinen nach dem Lauf in der Liste.
|
||
$effect(() => {
|
||
const id = selected;
|
||
untrack(() => {
|
||
loadBatch(id);
|
||
if (id !== null && !batches.some((b) => b.id === id)) loadBatches();
|
||
});
|
||
});
|
||
|
||
async function showSteps(run: RunRow) {
|
||
if (selected === null) return;
|
||
detail = { run, steps: await api.steps(selected, run) };
|
||
}
|
||
|
||
// Angebundene Modelle zuerst, dann die Referenzen (von Hand gelöst, ohne Rang).
|
||
let ordered = $derived(
|
||
ranking ? [...ranking.models.filter((m) => !m.external), ...ranking.models.filter((m) => m.external)] : [],
|
||
);
|
||
let bestRef = $derived(ranking?.models.find((m) => m.external) ?? null);
|
||
function refPct(group: string): number | null {
|
||
return bestRef?.groups.find((g) => g.group === group)?.percent ?? null;
|
||
}
|
||
|
||
// Kleinste Zahl gewerteter Durchläufe in einer Zelle der Matrix.
|
||
let minRepeats = $derived(ranking && ranking.cells.length > 0 ? Math.min(...ranking.cells.map((c) => c.runs)) : 0);
|
||
|
||
async function openCell(model: string, task: string) {
|
||
const r = rows.find((x) => x.model === model && x.task_id === task);
|
||
if (!r) return;
|
||
try {
|
||
await showSteps(r);
|
||
setTimeout(() => document.getElementById("run-detail")?.scrollIntoView({ behavior: "smooth", block: "start" }), 50);
|
||
} catch (e) {
|
||
error = String(e);
|
||
}
|
||
}
|
||
|
||
function cell(model: string, task: string) {
|
||
return ranking?.cells.find((c) => c.model === model && c.task_id === task);
|
||
}
|
||
|
||
function batchLabel(b: BatchInfo): string {
|
||
return `Batch ${b.id} · ${b.created_at.slice(0, 16)} · ${b.runs} Läufe`;
|
||
}
|
||
|
||
// Bereiche mit wenigen Aufgaben sind nur grobe Hinweise.
|
||
const FEW_TASKS = 3;
|
||
</script>
|
||
|
||
<section class="card">
|
||
<div class="head">
|
||
<h2>Bewertung</h2>
|
||
{#if batches.length > 0}
|
||
<select bind:value={selected} aria-label="Batch wählen">
|
||
{#each batches as b (b.id)}
|
||
<option value={b.id}>{batchLabel(b)}</option>
|
||
{/each}
|
||
</select>
|
||
{/if}
|
||
</div>
|
||
|
||
{#if error}<p class="error">{error}</p>{/if}
|
||
{#if batches.length === 0 && !error}
|
||
<p class="muted">Noch keine Ergebnisse. Starte im Reiter „Benchmark“ einen Lauf.</p>
|
||
{/if}
|
||
{#if loading}<p class="muted">Lade …</p>{/if}
|
||
|
||
{#if ranking && ranking.models.length > 0}
|
||
<div class="board">
|
||
{#each ordered as m (m.model)}
|
||
<article class="mcard" class:ref={m.external} data-rank={m.rank}>
|
||
<div class="badge r{m.external ? 5 : Math.min(m.rank, 4)}" aria-label={m.external ? "Referenz" : `Platz ${m.rank}`}>
|
||
{m.external ? "R" : m.rank}
|
||
</div>
|
||
<div class="mhead">
|
||
<h3 class="mname">
|
||
{m.model}
|
||
{#if m.external}<span class="chip" title="Von Hand außerhalb der App gelöst, anderes Harness, zählt nicht im Rang">Referenz · extern</span>{/if}
|
||
</h3>
|
||
<div class="stats">
|
||
<span title="Bestandene Läufe">✔ {m.successes}/{m.runs}</span>
|
||
{#if !m.external}
|
||
<span title="Median der Laufzeit">⏱ {fmtDuration(m.median_duration_ms)}</span>
|
||
<span title="Tokens pro Sekunde: Tokens geteilt durch die gesamte Laufzeit eines Laufs, also inklusive Tool- und Prüfzeit. Nicht die reine Erzeugungsgeschwindigkeit.">⚡ {fmtTps(m.median_tps)}</span>
|
||
<span title="Durchschnittlich erzeugte Tokens je Lauf">∅ {Math.round(m.mean_completion_tokens)} Tokens</span>
|
||
{:else}
|
||
<span>Zeit und Tokens nicht gemessen</span>
|
||
{/if}
|
||
</div>
|
||
</div>
|
||
<div class="total">
|
||
<div class="pct big" style:color={pctColor(m.total_percent)}>{fmtPct(m.total_percent)}</div>
|
||
<div class="label">Gesamt</div>
|
||
</div>
|
||
<div class="groups">
|
||
{#each m.groups as g (g.group)}
|
||
<div class="g" title={groupLabel(g.group)}>
|
||
<div class="gtop">
|
||
<span><b>{g.group}</b> {groupLabel(g.group)}</span>
|
||
{#if g.percent === null}
|
||
<span class="muted">–</span>
|
||
{:else}
|
||
<span class="pct" style:color={pctColor(g.percent)}>{fmtPct(g.percent)}</span>
|
||
{/if}
|
||
</div>
|
||
<div class="meter">
|
||
{#if g.percent !== null}
|
||
<div class="f" style:width="{g.percent}%" style:background={pctColor(g.percent)}></div>
|
||
{/if}
|
||
{#if !m.external && refPct(g.group) !== null}
|
||
<div class="tick" style:left="{refPct(g.group)}%" title="Referenz {bestRef?.model}: {fmtPct(refPct(g.group))}"></div>
|
||
{/if}
|
||
</div>
|
||
{#if g.percent !== null}
|
||
<div class="n" class:few={g.tasks < FEW_TASKS} title={g.tasks < FEW_TASKS ? "Wenige Aufgaben: der Wert ist nur ein grober Hinweis." : ""}>
|
||
{g.tasks} Aufg.{g.tasks < FEW_TASKS ? " (grob)" : ""}
|
||
</div>
|
||
{/if}
|
||
</div>
|
||
{/each}
|
||
</div>
|
||
{#if m.weakest_group}
|
||
<div class="weak">Schwächster Bereich: {m.weakest_group} · {groupLabel(m.weakest_group)}</div>
|
||
{/if}
|
||
</article>
|
||
{/each}
|
||
</div>
|
||
|
||
{#if bestRef}
|
||
<p class="muted small legend">
|
||
<span class="tick-demo"></span> Strich im Balken = Referenz <strong>{bestRef.model}</strong> (extern, von Hand gelöst, anderes Harness).
|
||
</p>
|
||
{/if}
|
||
|
||
{#if minRepeats < 3}
|
||
<p class="notice">
|
||
Pro Aufgabe {minRepeats === 1 ? "gab es nur 1 Durchlauf" : `gab es nur ${minRepeats} Durchläufe`}. Dann können Unterschiede
|
||
zwischen Modellen Zufall sein, und die Rangfolge ist nur ein Hinweis. Für belastbare Werte mindestens 3 Durchläufe wählen.
|
||
</p>
|
||
{/if}
|
||
|
||
{#if ranking.excluded_runs > 0}
|
||
<p class="muted">
|
||
{ranking.excluded_runs} Lauf/Läufe sind nicht gewertet, weil der Modell-Server oder die Umgebung ausfiel. Sie
|
||
fließen nicht in die Prozentwerte ein. Beim Fortsetzen eines Batches werden sie wiederholt.
|
||
</p>
|
||
{/if}
|
||
|
||
<details class="how">
|
||
<summary>So wird bewertet</summary>
|
||
<ul>
|
||
<li>
|
||
Die Bewertung ist <strong>absolut</strong>, nicht im Vergleich zu einem Referenzmodell. 100 % heißt: alle
|
||
Prüfungen der Aufgaben bestanden.
|
||
</li>
|
||
<li>
|
||
Je Aufgabe zählt der Mittelwert der Durchläufe. Teilpunkte aus <code>check.sh</code> gehen anteilig ein.
|
||
</li>
|
||
<li>
|
||
Wert je Bereich: gewichteter Mittelwert der Aufgaben im Bereich. Gesamt: gewichteter Mittelwert über alle
|
||
Aufgaben des Batches. Die Gewichte stehen als <code>weight</code> in <code>task.toml</code>.
|
||
</li>
|
||
<li>Fehlt einem Modell ein Bereich, bleibt das Feld leer und zählt nicht in die Gesamtnote.</li>
|
||
<li>Die Reihenfolge richtet sich nach der Gesamtnote. Bei Gleichstand gewinnt die kürzere Median-Dauer.</li>
|
||
<li>Bereiche mit weniger als {FEW_TASKS} Aufgaben sind nur grobe Hinweise.</li>
|
||
</ul>
|
||
</details>
|
||
|
||
<h3>Aufgaben im Detail <span class="muted small">Zelle anklicken öffnet den Lauf</span></h3>
|
||
<div class="scroll">
|
||
<table class="matrix">
|
||
<thead>
|
||
<tr>
|
||
<th>Modell</th>
|
||
{#each ranking.tasks as t (t.id)}
|
||
<th class="num" title={groupLabel(t.group)}>{t.id}</th>
|
||
{/each}
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{#each ranking.models as m (m.model)}
|
||
<tr>
|
||
<td>{m.model}</td>
|
||
{#each ranking.tasks as t (t.id)}
|
||
{@const c = cell(m.model, t.id)}
|
||
<td
|
||
class="num clickable"
|
||
onclick={() => openCell(m.model, t.id)}
|
||
style:background={c ? `color-mix(in srgb, ${pctColor(c.mean_score * 100)} 28%, transparent)` : ""}
|
||
title={c ? `${Math.round(c.mean_score * 100)} %, ${c.successes} von ${c.runs} bestanden` : "keine Läufe"}
|
||
>
|
||
{c ? `${Math.round(c.mean_score * 100)} %` : "–"}
|
||
</td>
|
||
{/each}
|
||
</tr>
|
||
{/each}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
|
||
<h3>
|
||
Einzelne Läufe
|
||
<button class="link" onclick={() => (showRuns = !showRuns)}>{showRuns ? "ausblenden" : `anzeigen (${rows.length})`}</button>
|
||
</h3>
|
||
{#if showRuns}
|
||
<div class="scroll">
|
||
<table>
|
||
<thead>
|
||
<tr>
|
||
<th>Modell</th>
|
||
<th>Aufgabe</th>
|
||
<th class="num">Durchlauf</th>
|
||
<th>Ergebnis</th>
|
||
<th class="num">Score</th>
|
||
<th class="num">Schritte</th>
|
||
<th class="num">Dauer</th>
|
||
<th></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{#each rows as r (`${r.model}|${r.task_id}|${r.repeat_idx}`)}
|
||
<tr>
|
||
<td>{r.model}</td>
|
||
<td>{r.task_id}</td>
|
||
<td class="num">{r.repeat_idx}</td>
|
||
<td class={r.error_class === "ok" ? "ok" : isInfrastructure(r.error_class) ? "muted" : "error"}>
|
||
{errorLabel(r.error_class)}
|
||
{#if isInfrastructure(r.error_class)}<span class="chip" title="Zählt nicht in die Bewertung">nicht gewertet</span>{/if}
|
||
</td>
|
||
<td class="num">{Math.round(r.score * 100)} %</td>
|
||
<td class="num">{r.steps}</td>
|
||
<td class="num">{fmtDuration(r.duration_ms)}</td>
|
||
<td><button onclick={() => showSteps(r)}>Schritte</button></td>
|
||
</tr>
|
||
{/each}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
{/if}
|
||
|
||
{#if detail}
|
||
<div class="detail" id="run-detail">
|
||
<h3>
|
||
Schritte: {detail.run.model} · {detail.run.task_id} · Durchlauf {detail.run.repeat_idx}
|
||
<button class="link" onclick={() => (detail = null)}>schließen</button>
|
||
</h3>
|
||
{#if detail.run.external}
|
||
<p class="muted">Extern gelöst, keine Schritte aufgezeichnet. Der Ergebnisordner steht unter <code>{detail.run.artifact_path ?? "unbekannt"}</code>.</p>
|
||
{/if}
|
||
{#if detail.run.check_output}
|
||
<p class="muted">Prüfung (<code>check.sh</code>):</p>
|
||
<pre>{detail.run.check_output}</pre>
|
||
{/if}
|
||
<ol class="steps">
|
||
{#each detail.steps as st (st.idx)}
|
||
<li>
|
||
<strong>{st.role}</strong>
|
||
{#if st.tool_name}<span class="chip">{st.tool_name}</span> <code>{st.tool_args_json ?? ""}</code>{/if}
|
||
{#if st.content}<pre>{st.content}</pre>{/if}
|
||
</li>
|
||
{/each}
|
||
</ol>
|
||
</div>
|
||
{/if}
|
||
{:else if ranking && !loading}
|
||
<p class="muted">Dieser Batch hat noch keine fertigen Läufe.</p>
|
||
{/if}
|
||
</section>
|
||
|
||
<style>
|
||
.head {
|
||
display: flex;
|
||
gap: 1rem;
|
||
align-items: center;
|
||
flex-wrap: wrap;
|
||
margin-bottom: 0.8rem;
|
||
}
|
||
.head h2 {
|
||
margin: 0;
|
||
flex: 1;
|
||
}
|
||
.head select {
|
||
max-width: 100%;
|
||
}
|
||
.scroll {
|
||
overflow-x: auto;
|
||
margin-bottom: 1rem;
|
||
}
|
||
.matrix th {
|
||
text-transform: none;
|
||
}
|
||
.board {
|
||
display: grid;
|
||
gap: 0.9rem;
|
||
margin-bottom: 1.2rem;
|
||
}
|
||
.mcard {
|
||
position: relative;
|
||
display: grid;
|
||
grid-template-columns: auto 1fr auto;
|
||
grid-template-areas:
|
||
"badge head total"
|
||
"groups groups groups"
|
||
"weak weak weak";
|
||
gap: 0.4rem 1rem;
|
||
align-items: center;
|
||
padding: 1rem 1.2rem;
|
||
background: var(--surface-2);
|
||
border: 1px solid var(--border);
|
||
border-radius: 12px;
|
||
}
|
||
.mcard[data-rank="1"] {
|
||
border-color: color-mix(in srgb, var(--gold) 60%, var(--border));
|
||
background: linear-gradient(135deg, color-mix(in srgb, var(--gold) 10%, var(--surface-2)), var(--surface-2) 60%);
|
||
}
|
||
.badge {
|
||
grid-area: badge;
|
||
width: 2.6rem;
|
||
height: 2.6rem;
|
||
border-radius: 50%;
|
||
display: grid;
|
||
place-items: center;
|
||
font-weight: 800;
|
||
font-size: 1.15rem;
|
||
color: #1a1005;
|
||
background: var(--muted);
|
||
}
|
||
.badge.r1 { background: var(--gold); }
|
||
.badge.r2 { background: var(--silver); }
|
||
.badge.r3 { background: var(--bronze); }
|
||
.badge.r4 { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
|
||
.mhead { grid-area: head; min-width: 0; }
|
||
.mname { margin: 0; font-size: 1.1rem; overflow-wrap: anywhere; }
|
||
.stats {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 0.2rem 1rem;
|
||
color: var(--muted);
|
||
font-size: 0.85rem;
|
||
font-variant-numeric: tabular-nums;
|
||
}
|
||
.total { grid-area: total; text-align: right; }
|
||
.total .label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
|
||
.groups {
|
||
grid-area: groups;
|
||
display: grid;
|
||
grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
|
||
gap: 0.7rem 1.2rem;
|
||
margin-top: 0.6rem;
|
||
}
|
||
.gtop { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.85rem; }
|
||
.gtop b { color: var(--accent); }
|
||
.weak { grid-area: weak; font-size: 0.8rem; color: var(--muted); }
|
||
.pct {
|
||
font-weight: 700;
|
||
font-variant-numeric: tabular-nums;
|
||
}
|
||
.pct.big {
|
||
font-size: 2.2rem;
|
||
line-height: 1;
|
||
}
|
||
.meter {
|
||
position: relative;
|
||
height: 7px;
|
||
background: var(--bg);
|
||
border-radius: 999px;
|
||
margin: 0.25rem 0;
|
||
}
|
||
.meter .f {
|
||
border-radius: 999px;
|
||
}
|
||
.tick,
|
||
.tick-demo {
|
||
background: var(--text);
|
||
border-radius: 2px;
|
||
}
|
||
.tick {
|
||
position: absolute;
|
||
top: -3px;
|
||
bottom: -3px;
|
||
width: 3px;
|
||
margin-left: -1px;
|
||
}
|
||
.tick-demo {
|
||
display: inline-block;
|
||
width: 3px;
|
||
height: 0.9rem;
|
||
vertical-align: middle;
|
||
}
|
||
.legend {
|
||
margin: 0 0 0.8rem;
|
||
}
|
||
.mcard.ref {
|
||
border-style: dashed;
|
||
}
|
||
.badge.r5 {
|
||
background: var(--surface);
|
||
color: var(--accent);
|
||
border: 1px dashed var(--accent);
|
||
}
|
||
.meter .f {
|
||
height: 100%;
|
||
}
|
||
.n {
|
||
font-size: 0.75rem;
|
||
color: var(--muted);
|
||
}
|
||
.n.few {
|
||
color: var(--danger);
|
||
}
|
||
.notice {
|
||
border: 1px solid color-mix(in srgb, var(--accent) 50%, var(--border));
|
||
background: var(--accent-soft);
|
||
border-radius: 10px;
|
||
padding: 0.6rem 0.9rem;
|
||
margin: 0 0 1rem;
|
||
font-size: 0.9rem;
|
||
}
|
||
td.clickable {
|
||
cursor: pointer;
|
||
}
|
||
td.clickable:hover {
|
||
outline: 2px solid var(--accent);
|
||
outline-offset: -2px;
|
||
}
|
||
.how {
|
||
margin: 0.5rem 0 1.2rem;
|
||
color: var(--muted);
|
||
}
|
||
.how summary {
|
||
cursor: pointer;
|
||
}
|
||
.detail {
|
||
margin-top: 1rem;
|
||
border-top: 1px solid var(--border);
|
||
padding-top: 1rem;
|
||
}
|
||
.steps pre,
|
||
.detail > pre {
|
||
white-space: pre-wrap;
|
||
overflow-wrap: anywhere;
|
||
max-height: 12rem;
|
||
overflow-y: auto;
|
||
background: var(--bg);
|
||
border: 1px solid var(--border);
|
||
border-radius: 6px;
|
||
padding: 0.5rem;
|
||
margin: 0.3rem 0;
|
||
}
|
||
</style>
|