feat: Oberfläche neu, Modell-Adapter wählbar, Bewertung je Bereich
Die erste Fassung der Oberfläche war inhaltlich und optisch schwach. Neu: drei Reiter (Benchmark, Ergebnisse, Einstellungen). Modelle werden in den Einstellungen mit Adapter (Ollama oder OpenAI-kompatibel), URL, Modell-ID und Schlüssel-Variable angelegt, mit Verbindungstest. config.toml speichert die Liste. Bewertung absolut in Prozent: ein Wert je Bereich A bis D und eine Gesamtnote, gewichtet nach weight. Batch-Verlauf, Schritt-Ansicht, Erklärung der Bewertung. 55 Unit-Tests grün, svelte-check ohne Fehler. Im Browser mit Beispieldaten geprüft, nicht in der echten App. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
279
src/lib/BenchPanel.svelte
Normal file
279
src/lib/BenchPanel.svelte
Normal file
@ -0,0 +1,279 @@
|
||||
<script lang="ts">
|
||||
import { onMount, onDestroy } from "svelte";
|
||||
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { api, groupLabel, type BatchEvent, type LoadReport, type ModelInfo, type TaskInfo } from "$lib/api";
|
||||
|
||||
let {
|
||||
models,
|
||||
tasks,
|
||||
ongotosettings,
|
||||
onfinished,
|
||||
}: {
|
||||
models: ModelInfo[];
|
||||
tasks: LoadReport | null;
|
||||
ongotosettings: () => void;
|
||||
onfinished: (batchId: number) => void;
|
||||
} = $props();
|
||||
|
||||
let chosenModels = $state<string[]>([]);
|
||||
let chosenTasks = $state<string[]>([]);
|
||||
let repeats = $state(1);
|
||||
let running = $state(false);
|
||||
let error = $state("");
|
||||
let progress = $state<{ done: number; total: number } | null>(null);
|
||||
let log = $state<{ text: string; cls: string }[]>([]);
|
||||
let current = $state("");
|
||||
let finishedBatch = $state<number | null>(null);
|
||||
let cancelled = $state(false);
|
||||
|
||||
let unlisten: UnlistenFn | null = null;
|
||||
|
||||
onMount(async () => {
|
||||
unlisten = await listen<BatchEvent>("batch-event", (ev) => onEvent(ev.payload));
|
||||
});
|
||||
onDestroy(() => unlisten?.());
|
||||
|
||||
function onEvent(e: BatchEvent) {
|
||||
if (e.kind === "progress") {
|
||||
progress = { done: e.done, total: e.total };
|
||||
return;
|
||||
}
|
||||
if (e.kind === "model_unavailable") {
|
||||
log.push({ text: `${e.model}: nicht erreichbar (${e.reason})`, cls: "error" });
|
||||
return;
|
||||
}
|
||||
const label = `${e.model} · ${e.task} · Durchlauf ${e.repeat}`;
|
||||
if (e.kind === "run_started") {
|
||||
current = label;
|
||||
} else if (e.kind === "run_skipped") {
|
||||
log.push({ text: `übersprungen: ${label}`, cls: "muted" });
|
||||
} else if (e.kind === "run_finished") {
|
||||
const ok = e.class === "ok";
|
||||
log.push({
|
||||
text: `${ok ? "bestanden" : e.class}: ${label}, ${Math.round(e.score * 100)} %`,
|
||||
cls: ok ? "ok" : "error",
|
||||
});
|
||||
current = "";
|
||||
}
|
||||
}
|
||||
|
||||
// Aufgaben nach Bereich gruppiert.
|
||||
let byGroup = $derived.by(() => {
|
||||
const m = new Map<string, TaskInfo[]>();
|
||||
for (const t of tasks?.tasks ?? []) {
|
||||
if (!m.has(t.group)) m.set(t.group, []);
|
||||
m.get(t.group)!.push(t);
|
||||
}
|
||||
return [...m.entries()].sort((a, b) => a[0].localeCompare(b[0]));
|
||||
});
|
||||
|
||||
function toggle(list: string[], id: string): string[] {
|
||||
return list.includes(id) ? list.filter((x) => x !== id) : [...list, id];
|
||||
}
|
||||
|
||||
function groupAll(group: string, on: boolean) {
|
||||
const ids = (byGroup.find(([g]) => g === group)?.[1] ?? []).map((t) => t.id);
|
||||
chosenTasks = on
|
||||
? [...new Set([...chosenTasks, ...ids])]
|
||||
: chosenTasks.filter((id) => !ids.includes(id));
|
||||
}
|
||||
|
||||
let totalRuns = $derived(chosenModels.length * chosenTasks.length * repeats);
|
||||
let canStart = $derived(!running && chosenModels.length > 0 && chosenTasks.length > 0 && repeats >= 1);
|
||||
|
||||
async function start() {
|
||||
error = "";
|
||||
log = [];
|
||||
progress = null;
|
||||
finishedBatch = null;
|
||||
cancelled = false;
|
||||
running = true;
|
||||
try {
|
||||
const s = await api.startBatch($state.snapshot(chosenModels), $state.snapshot(chosenTasks), repeats, "");
|
||||
finishedBatch = s.batch_id;
|
||||
cancelled = s.cancelled;
|
||||
} catch (e) {
|
||||
error = String(e);
|
||||
} finally {
|
||||
running = false;
|
||||
current = "";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if models.length === 0}
|
||||
<section class="card">
|
||||
<h2>Noch kein Modell angebunden</h2>
|
||||
<p class="muted">Bevor ein Benchmark laufen kann, braucht coding-bench mindestens ein Modell.</p>
|
||||
<button class="primary" onclick={ongotosettings}>Modell in den Einstellungen anlegen</button>
|
||||
</section>
|
||||
{:else}
|
||||
<section class="card">
|
||||
<h2>1. Modelle</h2>
|
||||
<div class="choices">
|
||||
{#each models as m (m.name)}
|
||||
<label class="choice">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={chosenModels.includes(m.name)}
|
||||
disabled={running}
|
||||
onchange={() => (chosenModels = toggle(chosenModels, m.name))}
|
||||
/>
|
||||
<span>
|
||||
<strong>{m.name}</strong>
|
||||
<span class="muted">{m.adapter === "ollama" ? "Ollama" : "OpenAI-kompatibel"} · {m.url}</span>
|
||||
</span>
|
||||
</label>
|
||||
{/each}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>2. Aufgaben</h2>
|
||||
{#if !tasks}
|
||||
<p class="muted">Lade Aufgaben …</p>
|
||||
{:else if tasks.tasks.length === 0}
|
||||
<p class="error">Keine gültigen Aufgaben gefunden.</p>
|
||||
{/if}
|
||||
{#each byGroup as [group, list] (group)}
|
||||
<div class="group">
|
||||
<div class="group-head">
|
||||
<h3>{group} · {groupLabel(group)} <span class="muted">({list.length})</span></h3>
|
||||
<button class="link" disabled={running} onclick={() => groupAll(group, true)}>alle</button>
|
||||
<button class="link" disabled={running} onclick={() => groupAll(group, false)}>keine</button>
|
||||
</div>
|
||||
{#each list as t (t.id)}
|
||||
<label class="choice">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={chosenTasks.includes(t.id)}
|
||||
disabled={running}
|
||||
onchange={() => (chosenTasks = toggle(chosenTasks, t.id))}
|
||||
/>
|
||||
<span><strong>{t.id}</strong> {t.title}</span>
|
||||
</label>
|
||||
{/each}
|
||||
</div>
|
||||
{/each}
|
||||
{#if tasks && tasks.errors.length > 0}
|
||||
<details>
|
||||
<summary class="error">{tasks.errors.length} Aufgabe(n) mit Fehlern</summary>
|
||||
<ul>
|
||||
{#each tasks.errors as e (e.dir)}
|
||||
<li><code>{e.dir}</code>: {e.message}</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</details>
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>3. Starten</h2>
|
||||
<div class="start">
|
||||
<label>
|
||||
Durchläufe je Aufgabe
|
||||
<input type="number" min="1" max="20" bind:value={repeats} disabled={running} />
|
||||
</label>
|
||||
<p class="muted">
|
||||
{#if totalRuns > 0}{totalRuns} Läufe: {chosenModels.length} Modell(e) × {chosenTasks.length} Aufgabe(n) × {repeats}.{:else}Wähle Modelle und Aufgaben.{/if}
|
||||
Mehr Durchläufe machen die Prozentwerte verlässlicher.
|
||||
</p>
|
||||
<div class="buttons">
|
||||
<button class="primary" onclick={start} disabled={!canStart}>Benchmark starten</button>
|
||||
<button class="danger" onclick={() => api.cancelBatch()} disabled={!running}>Abbrechen</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if progress}
|
||||
<div class="bar" role="progressbar" aria-valuenow={progress.done} aria-valuemax={progress.total}>
|
||||
<div class="fill" style:width="{progress.total ? (100 * progress.done) / progress.total : 0}%"></div>
|
||||
</div>
|
||||
<p class="muted">{progress.done} von {progress.total} Läufen fertig</p>
|
||||
{/if}
|
||||
{#if current}<p>Läuft: <strong>{current}</strong></p>{/if}
|
||||
{#if error}<p class="error">{error}</p>{/if}
|
||||
{#if finishedBatch !== null}
|
||||
<p>
|
||||
{cancelled ? "Abgebrochen." : "Fertig."}
|
||||
<button class="link" onclick={() => onfinished(finishedBatch!)}>Ergebnisse ansehen</button>
|
||||
</p>
|
||||
{/if}
|
||||
{#if log.length > 0}
|
||||
<ul class="log">
|
||||
{#each log as l, i (i)}
|
||||
<li class={l.cls}>{l.text}</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
</section>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.choices {
|
||||
display: grid;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
.choice {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 0.6rem;
|
||||
padding: 0.25rem 0;
|
||||
}
|
||||
.choice .muted {
|
||||
margin-left: 0.5rem;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.group {
|
||||
margin-bottom: 0.9rem;
|
||||
}
|
||||
.group-head {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
.group-head h3 {
|
||||
flex: 1;
|
||||
margin: 0;
|
||||
}
|
||||
.start label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2rem;
|
||||
width: 12rem;
|
||||
font-size: 0.85rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
.start input {
|
||||
color: var(--text);
|
||||
font-size: 1rem;
|
||||
}
|
||||
.buttons {
|
||||
display: flex;
|
||||
gap: 0.6rem;
|
||||
margin-top: 0.6rem;
|
||||
}
|
||||
.bar {
|
||||
height: 10px;
|
||||
background: var(--surface-2);
|
||||
border-radius: 999px;
|
||||
overflow: hidden;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
.fill {
|
||||
height: 100%;
|
||||
background: var(--accent);
|
||||
transition: width 0.3s;
|
||||
}
|
||||
.log {
|
||||
list-style: none;
|
||||
padding: 0.6rem;
|
||||
margin: 0.8rem 0 0;
|
||||
max-height: 18rem;
|
||||
overflow-y: auto;
|
||||
background: var(--bg);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
font-family: ui-monospace, Menlo, monospace;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
</style>
|
||||
352
src/lib/ResultsPanel.svelte
Normal file
352
src/lib/ResultsPanel.svelte
Normal file
@ -0,0 +1,352 @@
|
||||
<script lang="ts">
|
||||
import { onMount, untrack } from "svelte";
|
||||
import {
|
||||
api,
|
||||
fmtDuration,
|
||||
fmtPct,
|
||||
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) };
|
||||
}
|
||||
|
||||
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="scroll">
|
||||
<table class="rank">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="num">#</th>
|
||||
<th>Modell</th>
|
||||
<th class="total">Gesamt</th>
|
||||
{#each ranking.groups as g (g)}
|
||||
<th class="grp" title={groupLabel(g)}>{g}<br /><span class="gl">{groupLabel(g)}</span></th>
|
||||
{/each}
|
||||
<th>Schwächster Bereich</th>
|
||||
<th class="num">Bestanden</th>
|
||||
<th class="num">Median-Dauer</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each ranking.models as m (m.model)}
|
||||
<tr>
|
||||
<td class="num">{m.rank}</td>
|
||||
<td><strong>{m.model}</strong></td>
|
||||
<td class="total">
|
||||
<div class="pct big" style:color={pctColor(m.total_percent)}>{fmtPct(m.total_percent)}</div>
|
||||
<div class="meter"><div style:width="{m.total_percent}%" style:background={pctColor(m.total_percent)}></div></div>
|
||||
</td>
|
||||
{#each m.groups as g (g.group)}
|
||||
<td class="grp">
|
||||
{#if g.percent === null}
|
||||
<span class="muted">–</span>
|
||||
{:else}
|
||||
<div class="pct" style:color={pctColor(g.percent)}>{fmtPct(g.percent)}</div>
|
||||
<div class="meter small"><div style:width="{g.percent}%" style:background={pctColor(g.percent)}></div></div>
|
||||
<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}
|
||||
</td>
|
||||
{/each}
|
||||
<td>
|
||||
{#if m.weakest_group}
|
||||
{m.weakest_group} · {groupLabel(m.weakest_group)}
|
||||
{:else}
|
||||
<span class="muted">–</span>
|
||||
{/if}
|
||||
</td>
|
||||
<td class="num">{m.successes} / {m.runs}</td>
|
||||
<td class="num">{fmtDuration(m.median_duration_ms)}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<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</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"
|
||||
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" : "error"}>{r.error_class === "ok" ? "bestanden" : r.error_class}</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">
|
||||
<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.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;
|
||||
}
|
||||
.rank td,
|
||||
.rank th {
|
||||
vertical-align: top;
|
||||
}
|
||||
.matrix th {
|
||||
text-transform: none;
|
||||
}
|
||||
.rank .total {
|
||||
min-width: 7.5rem;
|
||||
}
|
||||
.rank .grp {
|
||||
min-width: 6rem;
|
||||
}
|
||||
.gl {
|
||||
font-weight: 400;
|
||||
text-transform: none;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
.pct {
|
||||
font-weight: 700;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.pct.big {
|
||||
font-size: 1.6rem;
|
||||
line-height: 1.1;
|
||||
}
|
||||
.meter {
|
||||
height: 7px;
|
||||
background: var(--surface-2);
|
||||
border-radius: 999px;
|
||||
overflow: hidden;
|
||||
margin: 0.25rem 0;
|
||||
}
|
||||
.meter.small {
|
||||
height: 5px;
|
||||
}
|
||||
.meter > div {
|
||||
height: 100%;
|
||||
}
|
||||
.n {
|
||||
font-size: 0.75rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
.n.few {
|
||||
color: var(--danger);
|
||||
}
|
||||
.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>
|
||||
232
src/lib/SettingsPanel.svelte
Normal file
232
src/lib/SettingsPanel.svelte
Normal file
@ -0,0 +1,232 @@
|
||||
<script lang="ts">
|
||||
import { api, type ModelEntry, type ModelInfo, type ModelTest, type Paths, type RuntimeStatus } from "$lib/api";
|
||||
|
||||
let {
|
||||
models,
|
||||
paths,
|
||||
runtime,
|
||||
onsaved,
|
||||
}: {
|
||||
models: ModelInfo[];
|
||||
paths: Paths | null;
|
||||
runtime: RuntimeStatus | null;
|
||||
onsaved: (m: ModelInfo[]) => void;
|
||||
} = $props();
|
||||
|
||||
const ADAPTERS = [
|
||||
{ id: "ollama", label: "Ollama", hint: "http://host:11434" },
|
||||
{ id: "openai", label: "OpenAI-kompatibel", hint: "http://host:8082/v1" },
|
||||
];
|
||||
|
||||
function toEntry(m: ModelInfo): ModelEntry {
|
||||
return { name: m.name, adapter: m.adapter, url: m.url, model: m.model, api_key_env: m.api_key_env };
|
||||
}
|
||||
|
||||
// Bearbeitungsstand: Kopie beim Öffnen, bewusst vom Original gelöst. Gilt erst nach „Speichern“.
|
||||
// svelte-ignore state_referenced_locally
|
||||
let draft = $state<ModelEntry[]>(models.map(toEntry));
|
||||
let dirty = $state(false);
|
||||
let saveError = $state("");
|
||||
let saving = $state(false);
|
||||
let tests = $state<Record<string, ModelTest | "läuft">>({});
|
||||
|
||||
function markDirty() {
|
||||
dirty = true;
|
||||
saveError = "";
|
||||
}
|
||||
|
||||
function addModel() {
|
||||
draft.push({ name: "", adapter: "ollama", url: "", model: "", api_key_env: "" });
|
||||
markDirty();
|
||||
}
|
||||
|
||||
function removeModel(i: number) {
|
||||
draft.splice(i, 1);
|
||||
markDirty();
|
||||
}
|
||||
|
||||
function hintFor(adapter: string): string {
|
||||
return ADAPTERS.find((a) => a.id === adapter)?.hint ?? "";
|
||||
}
|
||||
|
||||
async function save() {
|
||||
saving = true;
|
||||
saveError = "";
|
||||
try {
|
||||
const saved = await api.saveModels($state.snapshot(draft));
|
||||
draft = saved.map(toEntry);
|
||||
dirty = false;
|
||||
onsaved(saved);
|
||||
} catch (e) {
|
||||
saveError = String(e);
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function test(name: string) {
|
||||
tests[name] = "läuft";
|
||||
try {
|
||||
tests[name] = await api.testModel(name);
|
||||
} catch (e) {
|
||||
tests[name] = { ok: false, duration_ms: 0, message: String(e) };
|
||||
}
|
||||
}
|
||||
|
||||
function savedInfo(name: string): ModelInfo | undefined {
|
||||
return models.find((m) => m.name === name);
|
||||
}
|
||||
</script>
|
||||
|
||||
<section class="card">
|
||||
<h2>Modelle</h2>
|
||||
<p class="muted">
|
||||
Jedes Modell hat einen Adapter. Er bestimmt, wie coding-bench mit dem Server spricht. Ein Schlüssel steht nie in der
|
||||
Konfiguration: Trage nur den Namen der Umgebungsvariable ein, aus der die App ihn beim Start liest.
|
||||
</p>
|
||||
|
||||
{#if draft.length === 0}
|
||||
<p class="muted">Noch kein Modell angebunden.</p>
|
||||
{/if}
|
||||
|
||||
{#each draft as m, i (i)}
|
||||
<div class="model">
|
||||
<div class="grid">
|
||||
<label>
|
||||
Name
|
||||
<input bind:value={m.name} oninput={markDirty} placeholder="z. B. Qwen3 lokal" />
|
||||
</label>
|
||||
<label>
|
||||
Adapter
|
||||
<select bind:value={m.adapter} onchange={markDirty}>
|
||||
{#each ADAPTERS as a (a.id)}
|
||||
<option value={a.id}>{a.label}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</label>
|
||||
<label class="wide">
|
||||
Server-URL
|
||||
<input bind:value={m.url} oninput={markDirty} placeholder={hintFor(m.adapter)} />
|
||||
</label>
|
||||
<label>
|
||||
Modell-ID beim Server
|
||||
<input bind:value={m.model} oninput={markDirty} placeholder="leer = Name" />
|
||||
</label>
|
||||
<label>
|
||||
Schlüssel-Variable
|
||||
<input bind:value={m.api_key_env} oninput={markDirty} placeholder="leer = kein Schlüssel" />
|
||||
</label>
|
||||
</div>
|
||||
<div class="row">
|
||||
{#if m.api_key_env && savedInfo(m.name)}
|
||||
{#if savedInfo(m.name)?.api_key_set}
|
||||
<span class="chip ok">Schlüssel gefunden</span>
|
||||
{:else}
|
||||
<span class="chip error">Variable {m.api_key_env} ist nicht gesetzt</span>
|
||||
{/if}
|
||||
{/if}
|
||||
<span class="spacer"></span>
|
||||
{#if tests[m.name] === "läuft"}
|
||||
<span class="muted">teste …</span>
|
||||
{:else if tests[m.name]}
|
||||
{@const t = tests[m.name] as ModelTest}
|
||||
<span class={t.ok ? "ok" : "error"}>
|
||||
{t.ok ? "Verbunden" : "Fehler"}: {t.message}
|
||||
{#if t.duration_ms}({(t.duration_ms / 1000).toFixed(1)} s){/if}
|
||||
</span>
|
||||
{/if}
|
||||
<button onclick={() => test(m.name)} disabled={dirty || !savedInfo(m.name)} title={dirty ? "Erst speichern" : ""}>
|
||||
Verbindung testen
|
||||
</button>
|
||||
<button class="danger" onclick={() => removeModel(i)}>Entfernen</button>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
<div class="row">
|
||||
<button onclick={addModel}>Modell hinzufügen</button>
|
||||
<span class="spacer"></span>
|
||||
{#if saveError}<span class="error">{saveError}</span>{/if}
|
||||
{#if dirty}<span class="muted">Ungespeicherte Änderungen</span>{/if}
|
||||
<button class="primary" onclick={save} disabled={!dirty || saving}>Speichern</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<h2>System</h2>
|
||||
<dl>
|
||||
<dt>Container</dt>
|
||||
<dd>
|
||||
{#if runtime}
|
||||
{#if runtime.available}
|
||||
<span class="ok">{runtime.program} bereit, {runtime.detail}</span>
|
||||
{:else}
|
||||
<span class="error">{runtime.program} nicht nutzbar: {runtime.detail}</span>
|
||||
{/if}
|
||||
{:else}
|
||||
<span class="muted">Prüfe …</span>
|
||||
{/if}
|
||||
</dd>
|
||||
{#if paths}
|
||||
<dt>Konfiguration</dt>
|
||||
<dd><code>{paths.config_file}</code></dd>
|
||||
<dt>Datenordner</dt>
|
||||
<dd><code>{paths.data_dir}</code></dd>
|
||||
<dt>Aufgabenordner</dt>
|
||||
<dd><code>{paths.tasks_dir}</code></dd>
|
||||
{/if}
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<style>
|
||||
.model {
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 0.8rem;
|
||||
margin-bottom: 0.8rem;
|
||||
background: var(--bg);
|
||||
}
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0.6rem 0.8rem;
|
||||
}
|
||||
.grid .wide {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.2rem;
|
||||
font-size: 0.85rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
label input,
|
||||
label select {
|
||||
color: var(--text);
|
||||
font-size: 1rem;
|
||||
}
|
||||
.row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
margin-top: 0.7rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.spacer {
|
||||
flex: 1;
|
||||
}
|
||||
dl {
|
||||
display: grid;
|
||||
grid-template-columns: max-content 1fr;
|
||||
gap: 0.4rem 1.2rem;
|
||||
margin: 0;
|
||||
}
|
||||
dt {
|
||||
color: var(--muted);
|
||||
}
|
||||
dd {
|
||||
margin: 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
</style>
|
||||
127
src/lib/api.ts
Normal file
127
src/lib/api.ts
Normal file
@ -0,0 +1,127 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
export type Paths = { config_file: string; data_dir: string; tasks_dir: string };
|
||||
|
||||
export type TaskInfo = { id: string; title: string; group: string; dir: string; weight: number };
|
||||
export type TaskError = { dir: string; message: string };
|
||||
export type LoadReport = { tasks: TaskInfo[]; errors: TaskError[] };
|
||||
|
||||
export type ModelEntry = {
|
||||
name: string;
|
||||
adapter: string;
|
||||
url: string;
|
||||
model: string;
|
||||
api_key_env: string;
|
||||
};
|
||||
export type ModelInfo = ModelEntry & { api_key_set: boolean };
|
||||
export type ModelTest = { ok: boolean; duration_ms: number; message: string };
|
||||
|
||||
export type RuntimeStatus = { program: string; available: boolean; detail: string };
|
||||
|
||||
export type BatchInfo = {
|
||||
id: number;
|
||||
created_at: string;
|
||||
note: string;
|
||||
repeats: number;
|
||||
runs: number;
|
||||
models: string;
|
||||
};
|
||||
export type BatchSummary = { batch_id: number; completed: number; skipped: number; cancelled: boolean };
|
||||
|
||||
export type RunRow = {
|
||||
model: string;
|
||||
task_id: string;
|
||||
repeat_idx: number;
|
||||
error_class: string;
|
||||
score: number;
|
||||
steps: number;
|
||||
prompt_tokens: number;
|
||||
completion_tokens: number;
|
||||
duration_ms: number;
|
||||
tps: number | null;
|
||||
summary: string | null;
|
||||
check_output: string;
|
||||
};
|
||||
|
||||
export type StepRow = {
|
||||
idx: number;
|
||||
role: string;
|
||||
content: string;
|
||||
tool_name: string | null;
|
||||
tool_args_json: string | null;
|
||||
tool_result: string | null;
|
||||
};
|
||||
|
||||
export type GroupScore = { group: string; percent: number | null; tasks: number; runs: number };
|
||||
export type ModelRank = {
|
||||
rank: number;
|
||||
model: string;
|
||||
total_percent: number;
|
||||
groups: GroupScore[];
|
||||
weakest_group: string | null;
|
||||
runs: number;
|
||||
successes: number;
|
||||
median_duration_ms: number;
|
||||
mean_completion_tokens: number;
|
||||
};
|
||||
export type MatrixCell = { model: string; task_id: string; runs: number; successes: number; mean_score: number };
|
||||
export type TaskColumn = { id: string; group: string };
|
||||
export type Ranking = {
|
||||
batch_id: number;
|
||||
groups: string[];
|
||||
models: ModelRank[];
|
||||
cells: MatrixCell[];
|
||||
tasks: TaskColumn[];
|
||||
};
|
||||
|
||||
export type BatchEvent =
|
||||
| { kind: "run_started"; model: string; task: string; repeat: number }
|
||||
| { kind: "run_finished"; model: string; task: string; repeat: number; class: string; score: number }
|
||||
| { kind: "run_skipped"; model: string; task: string; repeat: number }
|
||||
| { kind: "model_unavailable"; model: string; reason: string }
|
||||
| { kind: "progress"; done: number; total: number };
|
||||
|
||||
export const api = {
|
||||
paths: () => invoke<Paths>("get_paths"),
|
||||
tasks: () => invoke<LoadReport>("load_tasks"),
|
||||
runtime: () => invoke<RuntimeStatus>("runtime_status"),
|
||||
models: () => invoke<ModelInfo[]>("list_models"),
|
||||
saveModels: (models: ModelEntry[]) => invoke<ModelInfo[]>("save_models", { models }),
|
||||
testModel: (name: string) => invoke<ModelTest>("test_model", { name }),
|
||||
startBatch: (models: string[], taskIds: string[], repeats: number, note: string) =>
|
||||
invoke<BatchSummary>("start_batch", { models, taskIds, repeats, note }),
|
||||
cancelBatch: () => invoke<boolean>("cancel_batch"),
|
||||
batches: () => invoke<BatchInfo[]>("list_batches"),
|
||||
results: (batchId: number) => invoke<RunRow[]>("batch_results", { batchId }),
|
||||
ranking: (batchId: number) => invoke<Ranking>("batch_ranking", { batchId }),
|
||||
steps: (batchId: number, r: RunRow) =>
|
||||
invoke<StepRow[]>("run_steps", { batchId, model: r.model, taskId: r.task_id, repeatIdx: r.repeat_idx }),
|
||||
};
|
||||
|
||||
/** Namen der Bereiche (Gruppen aus SPEC 11). */
|
||||
export const GROUP_LABELS: Record<string, string> = {
|
||||
A: "Tool-Calling",
|
||||
B: "Kleine Coding-Aufgaben",
|
||||
C: "Agent im Repo",
|
||||
D: "Demos",
|
||||
"?": "Unbekannt",
|
||||
};
|
||||
|
||||
export function groupLabel(g: string): string {
|
||||
return GROUP_LABELS[g] ?? g;
|
||||
}
|
||||
|
||||
/** Farbe für einen Prozentwert: rot bei 0, gelb in der Mitte, grün bei 100. */
|
||||
export function pctColor(p: number): string {
|
||||
const hue = Math.max(0, Math.min(100, p)) * 1.2;
|
||||
return `hsl(${hue} 60% 42%)`;
|
||||
}
|
||||
|
||||
export function fmtPct(p: number | null): string {
|
||||
return p === null ? "–" : `${Math.round(p)} %`;
|
||||
}
|
||||
|
||||
export function fmtDuration(ms: number): string {
|
||||
const s = ms / 1000;
|
||||
return s < 90 ? `${s.toFixed(1)} s` : `${Math.floor(s / 60)} min ${Math.round(s % 60)} s`;
|
||||
}
|
||||
Reference in New Issue
Block a user