llm-host/llmhost/web/index.html
Neil Bantoc 623d093b81 Dashboard: a reasoning chooser, offering only what the model accepts
Reasoning effort isn't a backend flag -- vLLM's --reasoning-parser only parses
the output. It's a chat-template kwarg read per request, and the models differ:
Qwen3.8 27B's template takes enable_thinking plus reasoning_effort in
('low','medium','xhigh') and raises on anything else, while Ornith 1.5 9B takes
only enable_thinking. Note 'xhigh', not OpenAI's 'high'.

So the chooser is built from what the loaded model's own template actually reads
(hfcache.template_controls), with the level names from the catalog, which is the
part that can't be inferred -- a level the template doesn't know would make it
raise, so an undeclared or unreadable one is never offered or sent.

The proxy injects the setting into chat completions, with a key the client set
itself always winning, the same precedence mlx_lm gives its own
--chat-template-kwargs. Reading it from config per request (mtime-cached) means
the dashboard changes it with no restart, so the model stays loaded -- the
startup flag would have cost a full reload per change.

vLLM gets no control: llm-host runs it without a proxy, so there is nothing in
the path to inject the kwarg. The panel hides itself rather than pretend.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-11-03 02:15:12 -08:00

675 lines
35 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>llm-host</title>
<style>
:root {
--bg: #f6f7f9; --panel: #ffffff; --panel-2: #f0f2f5; --border: #e2e5ea;
--text: #16191d; --muted: #646c78; --faint: #9aa1ac;
--accent: #3b6ef5; --accent-weak: #e6edfe;
--ok: #1f9d55; --ok-weak: #e3f5ea; --warn: #b7791f; --warn-weak: #fbf1dc;
--bad: #d64545; --bad-weak: #fbe5e5;
--c1: #3b6ef5; --c2: #0f9d8a; --c3: #c2620f; --c4: #d13d5e; --c5: #8a5cf0; --c6: #2f9e44; --c7: #b5179e;
--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
color-scheme: light;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #0e1013; --panel: #161a1f; --panel-2: #1d2228; --border: #262c34;
--text: #e7eaee; --muted: #9099a5; --faint: #5f6873;
--accent: #6d93ff; --accent-weak: #1c2640;
--ok: #3ccf7f; --ok-weak: #143022; --warn: #e3a94a; --warn-weak: #33280f;
--bad: #f07272; --bad-weak: #3a1818;
--c1: #6d93ff; --c2: #3fc9b4; --c3: #f0954a; --c4: #f2708c; --c5: #a98bff; --c6: #5fd27a; --c7: #e67ad1;
color-scheme: dark;
}
}
* { box-sizing: border-box; }
body {
margin: 0; background: var(--bg); color: var(--text);
font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 20px 16px 48px; }
header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
h1 { font-size: 18px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
h1 span { color: var(--muted); font-weight: 500; }
.pill {
display: inline-flex; align-items: center; gap: 7px; padding: 3px 10px; border-radius: 999px;
font-size: 12.5px; font-weight: 600; background: var(--panel-2); color: var(--muted);
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ready { background: var(--ok-weak); color: var(--ok); }
.pill.loading { background: var(--warn-weak); color: var(--warn); }
.pill.loading::before { animation: pulse 1.2s infinite ease-in-out; }
.pill.failed { background: var(--bad-weak); color: var(--bad); }
@keyframes pulse { 50% { opacity: .25; } }
.spacer { flex: 1; }
.meta { color: var(--muted); font-size: 12.5px; }
.grid { display: grid; gap: 14px; }
.top { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
@media (max-width: 820px) { .top { grid-template-columns: minmax(0, 1fr); } }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; min-width: 0; }
.panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 12px; font-weight: 600; }
.current .name { font-size: 22px; font-weight: 650; letter-spacing: -0.015em; overflow-wrap: anywhere; }
.current .hwline { font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.current .repo { font-family: var(--mono); font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; margin-top: 2px; }
.loadline {
margin-top: 12px; padding: 9px 11px; border-radius: 8px; background: var(--warn-weak); color: var(--text);
font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; display: none;
}
.loadline b { color: var(--warn); font-family: system-ui, sans-serif; margin-right: 6px; }
.btns { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.effort { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.effort .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.effort .row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.effort select {
background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
padding: 6px 10px; font: inherit; font-size: 13px; min-width: 150px;
}
.effort select:disabled { color: var(--muted); }
.effort .s { color: var(--muted); font-size: 12px; margin-top: 7px; line-height: 1.45; }
button {
font: inherit; font-size: 13px; font-weight: 550; padding: 7px 13px; border-radius: 8px; cursor: pointer;
border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
}
button:hover:not(:disabled) { border-color: var(--faint); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
.profiles { display: flex; flex-direction: column; gap: 8px; }
.prof {
display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
border: 1px solid var(--border); background: var(--panel);
}
.prof.active { border-color: var(--accent); background: var(--accent-weak); }
.prof .info { flex: 1; min-width: 0; }
.prof .pn { font-weight: 600; }
.prof .pm { font-family: var(--mono); font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prof .dl { font-size: 11.5px; color: var(--warn); font-weight: 600; }
.excluded { margin-top: 12px; font-size: 12px; color: var(--faint); }
.excluded b { color: var(--muted); font-weight: 600; }
.prof .tag { font-size: 11.5px; color: var(--accent); font-weight: 600; white-space: nowrap; }
.tiles { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-top: 14px; }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.tile .k { font-size: 12px; color: var(--muted); }
.tile .v { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; margin-top: 2px; white-space: nowrap; }
.tile .v small { font-size: 12.5px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.tile .s { font-size: 11.5px; color: var(--faint); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 4px; border-radius: 2px; background: var(--panel-2); margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .4s; }
.charts { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 14px; }
.charts.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .charts.four { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 820px) { .charts, .charts.four { grid-template-columns: minmax(0, 1fr); } }
.chart .head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.chart .head span { font-size: 12px; color: var(--muted); }
.chart .head b { font-size: 13px; font-variant-numeric: tabular-nums; }
.chart svg { width: 100%; height: 90px; display: block; touch-action: pan-y; cursor: crosshair; }
.plot { position: relative; }
.plot .tip {
position: absolute; z-index: 2; pointer-events: none; display: none; white-space: nowrap;
background: var(--text); color: var(--bg); border-radius: 6px; padding: 4px 8px;
font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.plot .tip small { display: block; font-size: 11px; font-weight: 400; opacity: .72; }
.plot .dot {
position: absolute; z-index: 1; pointer-events: none; display: none;
width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--panel); transform: translate(-50%, -50%);
}
.chart .axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--faint); margin-top: 4px; }
.runs { margin-top: 14px; }
.runs .head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.runs .head h2 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.runs .head .sub { color: var(--muted); font-size: 12px; }
.runs .scroll { overflow-x: auto; }
.runs table { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.runs th, .runs td { padding: 5px 10px 5px 0; text-align: right; white-space: nowrap; }
.runs th:first-child, .runs td:first-child { text-align: left; padding-left: 0; }
.runs th { color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); font-size: 11.5px; }
.runs tbody tr + tr td { border-top: 1px solid color-mix(in srgb, var(--border) 55%, transparent); }
.runs td.none { color: var(--muted); }
.runs tr.aborted td:first-child::after { content: " cancelled"; color: var(--bad); font-size: 11px; }
.runs tfoot td { border-top: 1px solid var(--border); font-weight: 600; }
.runs .empty { color: var(--muted); font-size: 13px; padding: 6px 0 2px; }
details.logs { margin-top: 14px; }
details.logs summary { cursor: pointer; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; list-style: none; }
details.logs summary::before { content: "▸ "; }
details.logs[open] summary::before { content: "▾ "; }
pre {
margin: 12px 0 0; padding: 12px; border-radius: 8px; background: var(--panel-2); max-height: 380px; overflow: auto;
font: 11.5px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere;
}
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.overlay.show { display: flex; }
.dialog { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 20px; width: 100%; max-width: 420px; }
.dialog h3 { margin: 0 0 6px; font-size: 16px; }
.dialog p { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.dialog input {
width: 100%; font: 13px var(--mono); padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border);
background: var(--panel-2); color: var(--text); margin-bottom: 12px;
}
.dialog .err { color: var(--bad); font-size: 12.5px; min-height: 18px; margin: -6px 0 8px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
padding: 8px 14px; border-radius: 8px; font-size: 13px; opacity: 0; transition: opacity .25s; pointer-events: none; }
.toast.show { opacity: 1; }
</style>
</head>
<body>
<div class="wrap">
<header>
<h1>llm-host <span id="host"></span></h1>
<span id="phase" class="pill">…</span>
<span class="spacer"></span>
<span class="meta" id="uptime"></span>
<button id="logout" title="Forget API key">Sign out</button>
</header>
<div class="grid top">
<section class="panel current">
<h2>Serving</h2>
<div class="name" id="cur-name">—</div>
<div class="repo" id="cur-repo"></div>
<div class="hwline" id="hwline"></div>
<div class="loadline" id="loadline"><b id="load-title">Loading</b><span id="load-text"></span></div>
<div class="effort" id="effort" hidden>
<div class="k">Reasoning</div>
<div class="row">
<select id="effort-sel"></select>
<span class="meta" id="effort-state"></span>
</div>
<div class="s" id="effort-note"></div>
</div>
<div class="btns">
<button id="btn-restart">Restart</button>
<button id="btn-stop" class="danger">Stop</button>
<button id="btn-start" class="primary">Start</button>
</div>
</section>
<section class="panel">
<h2>Models</h2>
<div class="profiles" id="profiles"></div>
<div class="excluded" id="excluded"></div>
</section>
</div>
<div class="grid tiles">
<div class="tile"><div class="k">Generation</div><div class="v" id="t-gen">—</div><div class="s" id="t-gen-s"></div></div>
<div class="tile"><div class="k">Prompt processing</div><div class="v" id="t-prompt">—</div><div class="s" id="t-prompt-s"></div></div>
<div class="tile"><div class="k">Time to first token</div><div class="v" id="t-ttft">—</div><div class="s" id="t-ttft-s"></div></div>
<div class="tile"><div class="k">Requests</div><div class="v" id="t-req">—</div><div class="s" id="t-req-s"></div></div>
<div class="tile"><div class="k">KV cache</div><div class="v" id="t-kv">—</div><div class="bar"><i id="b-kv"></i></div></div>
<div class="tile"><div class="k">GPU</div><div class="v" id="t-util">—</div><div class="s" id="t-util-s"></div></div>
<div class="tile"><div class="k">VRAM</div><div class="v" id="t-mem">—</div><div class="bar"><i id="b-mem"></i></div></div>
<div class="tile"><div class="k">MTP acceptance</div><div class="v" id="t-spec">—</div><div class="s">speculative tokens kept</div></div>
<div class="tile"><div class="k">Prefix cache hits</div><div class="v" id="t-prefix">—</div><div class="s">prompt tokens reused</div></div>
</div>
<div class="grid charts four">
<div class="panel chart"><div class="head"><span>Generation tok/s</span><b id="c-gen-v"></b></div><svg id="c-gen" viewBox="0 0 300 90" preserveAspectRatio="none"></svg><div class="axis"><span>10 min ago</span><span>now</span></div></div>
<div class="panel chart"><div class="head"><span>Prompt processing tok/s</span><b id="c-prompt-v"></b></div><svg id="c-prompt" viewBox="0 0 300 90" preserveAspectRatio="none"></svg><div class="axis"><span>10 min ago</span><span>now</span></div></div>
<div class="panel chart"><div class="head"><span>Time to first token</span><b id="c-ttft-v"></b></div><svg id="c-ttft" viewBox="0 0 300 90" preserveAspectRatio="none"></svg><div class="axis"><span>10 min ago</span><span>now</span></div></div>
<div class="panel chart"><div class="head"><span>KV cache %</span><b id="c-kv-v"></b></div><svg id="c-kv" viewBox="0 0 300 90" preserveAspectRatio="none"></svg><div class="axis"><span>10 min ago</span><span>now</span></div></div>
</div>
<div class="grid charts" id="gpu-charts">
<div class="panel chart"><div class="head"><span>GPU utilization %</span><b id="c-util-v"></b></div><svg id="c-util" viewBox="0 0 300 90" preserveAspectRatio="none"></svg><div class="axis"><span>10 min ago</span><span>now</span></div></div>
<div class="panel chart" id="p-temp"><div class="head"><span>GPU temperature °C</span><b id="c-temp-v"></b></div><svg id="c-temp" viewBox="0 0 300 90" preserveAspectRatio="none"></svg><div class="axis"><span>10 min ago</span><span id="c-temp-max">0–100 °C</span><span>now</span></div></div>
<div class="panel chart" id="p-power"><div class="head"><span>GPU power W</span><b id="c-power-v"></b></div><svg id="c-power" viewBox="0 0 300 90" preserveAspectRatio="none"></svg><div class="axis"><span>10 min ago</span><span id="c-power-max"></span><span>now</span></div></div>
<div class="panel chart" id="p-nogpu" hidden><div class="head"><span>GPU temperature &amp; power</span></div><div class="empty" id="nogpu-why">not available on this hardware</div></div>
</div>
<section class="panel runs" id="runs">
<div class="head">
<h2>Completed requests</h2>
<span class="sub" id="runs-sub"></span>
</div>
<div class="scroll">
<table>
<thead><tr>
<th>Finished</th><th>Duration</th><th>TTFT</th>
<th>Prompt</th><th>Prompt tok/s</th>
<th>Generated</th><th>Gen tok/s</th><th>Peak KV</th>
</tr></thead>
<tbody id="runs-body"></tbody>
<tfoot id="runs-foot"></tfoot>
</table>
</div>
<div class="empty" id="runs-empty" hidden>No requests finished yet.</div>
</section>
<details class="panel logs" id="logs">
<summary>Server log</summary>
<pre id="log-text">…</pre>
</details>
</div>
<div class="overlay" id="auth">
<form class="dialog" id="auth-form">
<h3>API key</h3>
<p>Enter the API key from <code>~/.config/llm-host/api_key</code> on the server (or run <code>llmhost key</code>). It's kept in this browser only.</p>
<input id="auth-key" type="password" autocomplete="current-password" placeholder="sk-…" required>
<div class="err" id="auth-err"></div>
<button class="primary" type="submit">Continue</button>
</form>
</div>
<div class="toast" id="toast"></div>
<script>
const $ = (id) => document.getElementById(id);
let KEY = null;
try { KEY = localStorage.getItem("llmhost-key"); } catch (e) {}
let state = null;
let logTimer = null;
$("host").textContent = "· " + location.hostname;
function toast(msg) {
const t = $("toast"); t.textContent = msg; t.classList.add("show");
clearTimeout(t._h); t._h = setTimeout(() => t.classList.remove("show"), 2600);
}
async function api(path, opts = {}) {
const r = await fetch(path, { ...opts, headers: { "Authorization": "Bearer " + KEY, "Content-Type": "application/json" } });
if (r.status === 401) { showAuth("That key was rejected."); throw new Error("unauthorized"); }
const body = await r.json();
if (!r.ok) throw new Error(body.error || r.statusText);
return body;
}
function showAuth(err = "") { $("auth-err").textContent = err; $("auth").classList.add("show"); $("auth-key").focus(); }
$("auth-form").addEventListener("submit", (e) => {
e.preventDefault();
KEY = $("auth-key").value.trim();
try { localStorage.setItem("llmhost-key", KEY); } catch (e) {}
$("auth").classList.remove("show");
poll();
});
$("logout").onclick = () => { try { localStorage.removeItem("llmhost-key"); } catch (e) {} KEY = null; showAuth(); };
const fmt = {
n: (v, d = 0) => v == null ? "—" : v.toLocaleString(undefined, { maximumFractionDigits: d, minimumFractionDigits: d }),
pct: (v) => v == null ? "—" : Math.round(v) + "%",
big: (v) => v == null ? "—" : v >= 1e9 ? (v / 1e9).toFixed(2) + "B" : v >= 1e6 ? (v / 1e6).toFixed(1) + "M" : v >= 1e3 ? (v / 1e3).toFixed(1) + "k" : String(Math.round(v)),
dur: (s) => { if (s == null) return ""; s = Math.floor(s); const d = Math.floor(s / 86400), h = Math.floor(s % 86400 / 3600), m = Math.floor(s % 3600 / 60);
return d ? `${d}d ${h}h` : h ? `${h}h ${m}m` : m ? `${m}m ${s % 60}s` : `${s}s`; },
secs: (v) => v == null ? "—" : v < 1 ? Math.round(v * 1000) + " ms" : v < 10 ? v.toFixed(2) + " s" : v.toFixed(1) + " s",
ctx: (n) => n == null ? "" : n >= 1024 ? Math.round(n / 1024) + "k ctx" : n + " ctx",
};
function setV(id, value, unit) { $(id).innerHTML = value + (unit && value !== "—" ? `<small>${unit}</small>` : ""); }
function render(s) {
if (!s.models) return; // sampler hasn't run yet
state = s;
const busy = !!s.action || s.phase === "loading";
const ph = $("phase");
const labels = { ready: "Ready", loading: "Loading", stopped: "Stopped", failed: "Failed" };
ph.textContent = s.action ? ({ switch: "Switching", stop: "Stopping", start: "Starting", restart: "Restarting" }[s.action.kind]) : labels[s.phase] || s.phase;
ph.className = "pill " + (s.action ? "loading" : s.phase);
$("uptime").textContent = s.phase === "ready" && s.uptime ? "up " + fmt.dur(s.uptime) : "";
const prof = s.models.find((p) => p.name === s.active);
$("cur-name").textContent = s.phase === "stopped" ? "Nothing loaded" : (s.active || "—");
$("cur-repo").textContent = prof ? `${prof.repo} · ${prof.format}` : "";
$("hwline").textContent = [s.hardware, s.budget_gib ? `${s.budget_gib} GiB usable` : "", s.backend === "mlx" ? "MLX" : "vLLM"].filter(Boolean).join(" · ");
const ll = $("loadline");
if (s.phase === "loading" || s.phase === "failed") {
ll.style.display = "block";
if (s.phase === "loading" && prof && !prof.downloaded) $("load-title").dataset.dl = "1"; else delete $("load-title").dataset.dl;
$("load-title").textContent = s.phase === "failed" ? "Failed —" : ($("load-title").dataset.dl ? `Downloading ${prof.weights_gib} GiB, then loading —` : "Loading —");
$("load-text").textContent = s.last_log || (s.phase === "failed" ? "see server log below" : "starting…");
ll.style.background = s.phase === "failed" ? "var(--bad-weak)" : "";
} else ll.style.display = "none";
$("btn-stop").disabled = s.phase === "stopped" || !!s.action;
$("btn-restart").disabled = s.phase === "stopped" || !!s.action;
$("btn-start").disabled = !(s.phase === "stopped" || s.phase === "failed") || !!s.action;
const pr = $("profiles");
const want = JSON.stringify([s.models, s.active, busy, s.phase]);
if (pr._sig !== want) {
pr._sig = want;
pr.innerHTML = "";
for (const p of s.models) {
const isActive = p.name === s.active && s.phase !== "stopped";
const row = document.createElement("div");
row.className = "prof" + (isActive ? " active" : "");
row.innerHTML = `<div class="info"><div class="pn"></div><div class="pm"></div></div>`;
row.querySelector(".pn").textContent = p.name;
row.querySelector(".pm").textContent = `${p.format} · ${p.weights_gib} GiB · ~${fmt.ctx(p.est_context)}`;
row.querySelector(".pm").title = p.repo;
if (!p.downloaded) {
const dl = document.createElement("div"); dl.className = "dl"; dl.textContent = "Not downloaded yet";
row.querySelector(".info").appendChild(dl);
}
if (isActive) {
const tag = document.createElement("span"); tag.className = "tag";
tag.textContent = s.phase === "ready" && !s.action ? "Active" : "Loading…";
row.appendChild(tag);
} else {
const b = document.createElement("button"); b.textContent = p.downloaded ? "Load" : "Download & load"; b.disabled = busy;
b.onclick = () => switchTo(p);
row.appendChild(b);
}
pr.appendChild(row);
}
const ex = $("excluded");
ex.innerHTML = "";
if (s.excluded && s.excluded.length) {
ex.append("Too big for this hardware: ");
s.excluded.forEach((e, i) => {
const b = document.createElement("b"); b.textContent = e.name; b.title = e.reason;
ex.append(i ? ", " : "", b, ` (≥${e.smallest_gib} GiB)`);
});
}
}
const m = s.metrics || {}, g = s.gpu || {};
const live = s.phase === "ready";
setV("t-gen", live ? fmt.n(m.gen_tps, m.gen_tps < 10 ? 1 : 0) : "—", "tok/s");
$("t-gen-s").textContent = live && m.gen_total != null ? fmt.big(m.gen_total) + " generated" : "";
setV("t-prompt", live ? fmt.n(m.prompt_tps, 0) : "—", "tok/s");
$("t-prompt-s").textContent = live && m.prompt_total != null ? fmt.big(m.prompt_total) + " processed" : "";
// Latest measured value, kept while idle (a request has to start for a new one).
const tt = m.ttft_last != null ? fmt.secs(m.ttft_last).split(" ") : null;
$("t-ttft").innerHTML = live && tt ? `${tt[0]}<small>${tt[1]}</small>` : "—";
$("t-ttft-s").textContent = live && m.ttft_avg != null
? `avg ${fmt.secs(m.ttft_avg)} · ${fmt.big(m.ttft_count)} req` + (s.backend === "mlx" ? " (streamed)" : "")
: live ? "no requests yet" : "";
$("t-req").innerHTML = live ? `${fmt.n(m.running)}<small>running</small>` : "—";
$("t-req-s").textContent = live ? `${fmt.n(m.waiting)} waiting` + (m.preemptions ? ` · ${fmt.n(m.preemptions)} preempted` : "") : "";
setV("t-kv", live ? fmt.n(m.kv_pct, 1) : "—", "%");
$("b-kv").style.width = (live && m.kv_pct != null ? m.kv_pct : 0) + "%";
if (m.kv_bytes != null && m.kv_budget_bytes) {
$("t-kv").title = `${(m.kv_bytes / 1e9).toFixed(2)} GB of ${(m.kv_budget_bytes / 1e9).toFixed(0)} GB`
+ (m.kv_seqs != null ? ` · ${m.kv_seqs} sequences` : "");
}
setV("t-util", fmt.pct(g.util), "");
$("t-util-s").textContent = g.temp != null ? `${Math.round(g.temp)}°C · ${Math.round(g.power)} / ${Math.round(g.power_limit)} W` : "";
$("t-mem").innerHTML = g.mem_used != null ? `${(g.mem_used / 1024).toFixed(1)}<small>/ ${(g.mem_total / 1024).toFixed(0)} GiB</small>` : "—";
$("b-mem").style.width = (g.mem_total ? g.mem_used / g.mem_total * 100 : 0) + "%";
$("t-spec").textContent = live && m.spec_accept != null ? fmt.pct(m.spec_accept * 100) : "—";
$("t-prefix").textContent = live && m.prefix_hit != null ? fmt.pct(m.prefix_hit * 100) : "—";
const h = s.history || [];
chartTimes = h.map((p) => p.t);
chart("c-gen", h.map((p) => p.gen), "var(--c1)", null, (v) => fmt.n(v, 0) + " tok/s");
chart("c-prompt", h.map((p) => p.prompt), "var(--c6)", null, (v) => fmt.n(v, 0) + " tok/s");
chart("c-ttft", h.map((p) => p.ttft), "var(--c7)", null, (v) => fmt.secs(v));
chart("c-util", h.map((p) => p.util), "var(--c2)", 100, (v) => fmt.pct(v));
chart("c-kv", h.map((p) => p.kv), "var(--c3)", null, (v) => fmt.n(v, 1) + "%");
// Fixed scales so the shape means something: 0–100 °C, and 0 to the board power limit.
// Apple Silicon reports neither through any API that works without root (powermetrics
// needs sudo), so hide the panels instead of drawing two charts that can never fill.
const hasTP = g.temp != null || g.power != null || h.some((p) => p.temp != null || p.power != null);
$("p-temp").hidden = !hasTP;
$("p-power").hidden = !hasTP;
$("p-nogpu").hidden = hasTP;
$("gpu-charts").classList.toggle("four", false);
if (!hasTP) {
$("nogpu-why").textContent = s.kind === "apple"
? "macOS only exposes GPU temperature and power to root (powermetrics), so they aren't charted here."
: "not reported by this hardware";
} else {
chart("c-temp", h.map((p) => p.temp), "var(--c4)", 100, (v) => Math.round(v) + " °C");
$("c-temp-max").textContent = "0–100 °C";
const plim = g.power_limit || 600;
$("c-power-max").textContent = `0–${Math.round(plim)} W`;
chart("c-power", h.map((p) => p.power), "var(--c5)", plim, (v) => Math.round(v) + " W");
}
renderRuns(s);
renderEffort(s);
}
let effortBusy = false;
function renderEffort(s) {
const r = s.reasoning || {}, box = $("effort"), sel = $("effort-sel");
const opts = r.options || [];
// Hidden rather than disabled when there is nothing to choose: on vLLM there's no proxy
// to inject the kwarg, and a model whose template has no switches has nothing to offer.
box.hidden = !opts.length && !r.why;
if (!opts.length) {
sel.innerHTML = "";
sel.disabled = true;
$("effort-state").textContent = "";
$("effort-note").textContent = r.why || "";
return;
}
if (effortBusy) return;
const want = opts.map((o) => o.value).join("|");
if (sel.dataset.sig !== want) {
sel.dataset.sig = want;
sel.innerHTML = "";
for (const o of opts) {
const el = document.createElement("option");
el.value = o.value;
el.textContent = o.label;
sel.append(el);
}
}
sel.value = r.value || "default";
sel.disabled = s.phase !== "ready";
$("effort-state").textContent = s.phase === "ready" ? "" : "available once the model is ready";
$("effort-note").textContent = "Applies to requests that don't set their own; takes effect "
+ "on the next request, with no reload.";
}
$("effort-sel").onchange = async (e) => {
const value = e.target.value;
effortBusy = true;
try {
await api("/api/reasoning", { method: "POST", body: JSON.stringify({ value }) });
const opt = e.target.selectedOptions[0];
toast(`Reasoning: ${opt ? opt.textContent : value}`);
} catch (err) {
toast("Couldn't change reasoning");
} finally {
effortBusy = false;
poll();
}
};
function renderRuns(s) {
const runs = s.runs || [], body = $("runs-body"), foot = $("runs-foot");
$("runs-empty").hidden = runs.length > 0;
$("runs").hidden = s.backend !== "mlx" && runs.length === 0;
body.textContent = "";
foot.textContent = "";
if (!runs.length) {
$("runs-sub").textContent = s.backend === "mlx" ? "" : "per-request timings are only collected on MLX";
return;
}
const clock = (t) => new Date(t * 1000).toLocaleTimeString(undefined, { hour12: false });
const cell = (tr, text, cls) => {
const td = document.createElement("td");
td.textContent = text;
if (cls) td.className = cls;
tr.append(td);
return td;
};
const dash = (v, f) => (v == null ? ["—", "none"] : [f(v), ""]);
for (const r of runs) {
const tr = document.createElement("tr");
if (r.aborted) tr.className = "aborted";
cell(tr, clock(r.t));
cell(tr, ...dash(r.dur, fmt.secs));
cell(tr, ...dash(r.ttft, fmt.secs));
cell(tr, ...dash(r.prompt, (v) => fmt.big(v)));
cell(tr, ...dash(r.prompt_tps, (v) => fmt.n(v, 0)));
cell(tr, ...dash(r.gen, (v) => fmt.big(v)));
cell(tr, ...dash(r.gen_tps, (v) => fmt.n(v, 1)));
cell(tr, ...dash(r.kv_peak_pct, (v) => fmt.n(v, 1) + "%"));
body.append(tr);
}
// Averages over the runs shown, so the row means the same thing as the table above it.
const avg = (k) => {
const xs = runs.map((r) => r[k]).filter((v) => v != null);
return xs.length ? xs.reduce((a, b) => a + b, 0) / xs.length : null;
};
const peak = Math.max(...runs.map((r) => r.kv_peak_pct ?? 0));
const tr = document.createElement("tr");
cell(tr, `${runs.length} shown`);
cell(tr, ...dash(avg("dur"), fmt.secs));
cell(tr, ...dash(avg("ttft"), fmt.secs));
cell(tr, ...dash(avg("prompt"), (v) => fmt.big(v)));
cell(tr, ...dash(avg("prompt_tps"), (v) => fmt.n(v, 0)));
cell(tr, ...dash(avg("gen"), (v) => fmt.big(v)));
cell(tr, ...dash(avg("gen_tps"), (v) => fmt.n(v, 1)));
cell(tr, ...dash(peak > 0 ? peak : null, (v) => fmt.n(v, 1) + "%"));
foot.append(tr);
$("runs-sub").textContent = "newest first · averages below · tok/s split at first token";
}
const CW = 300, CH = 90, CN = 300; // chart viewBox width/height, max samples
let chartTimes = [];
function chart(id, vals, color, fixedMax, f) {
const svg = $(id), W = CW, H = CH, N = CN;
const pts = vals.slice(-N);
const times = chartTimes.slice(-N);
const last = [...pts].reverse().find((v) => v != null);
$(id + "-v").textContent = last != null ? f(last) : "";
const max = fixedMax || Math.max(1, ...pts.filter((v) => v != null)) * 1.15;
const x = (i) => W - (pts.length - 1 - i) * (W / (N - 1));
const y = (v) => H - 2 - (v / max) * (H - 4);
let d = "", area = "", segStart = null;
pts.forEach((v, i) => {
if (v == null) { if (segStart != null) { area += `L${x(i - 1)},${H}Z`; segStart = null; } return; }
if (segStart == null) { d += `M${x(i)},${y(v)}`; area += `M${x(i)},${H}L${x(i)},${y(v)}`; segStart = i; }
else { d += `L${x(i)},${y(v)}`; area += `L${x(i)},${y(v)}`; }
});
if (segStart != null) area += `L${x(pts.length - 1)},${H}Z`;
let dots = "";
pts.forEach((v, i) => {
if (v != null && pts[i - 1] == null && pts[i + 1] == null) dots += `M${x(i)},${y(v)}l0,0`;
});
svg.innerHTML =
`<line x1="0" x2="${W}" y1="${H - 1}" y2="${H - 1}" stroke="var(--border)" />` +
`<path d="${area}" fill="${color}" fill-opacity="0.12" />` +
`<path d="${d}" fill="none" stroke="${color}" stroke-width="1.75" vector-effect="non-scaling-stroke" stroke-linejoin="round" />` +
(dots ? `<path d="${dots}" fill="none" stroke="${color}" stroke-width="5" stroke-linecap="round" vector-effect="non-scaling-stroke" />` : "");
svg._data = { pts, times, color, f, x, y };
drawHover(svg);
}
// ---- hover crosshair ----
// The hover position is kept in viewBox units so it survives the 2s redraws:
// the cursor stays put and the tooltip follows whatever sample is now under it.
function attachHover(svg) {
const plot = document.createElement("div");
plot.className = "plot";
svg.parentNode.insertBefore(plot, svg);
plot.appendChild(svg);
svg._tip = Object.assign(document.createElement("div"), { className: "tip" });
svg._dot = Object.assign(document.createElement("div"), { className: "dot" });
plot.append(svg._tip, svg._dot);
const move = (e) => {
const r = svg.getBoundingClientRect();
svg._hoverVX = (e.clientX - r.left) / r.width * CW;
drawHover(svg);
};
svg.addEventListener("pointermove", move);
svg.addEventListener("pointerdown", move);
svg.addEventListener("pointerleave", () => { svg._hoverVX = null; drawHover(svg); });
}
function timeLabel(t) {
const now = state && state.time ? state.time : Date.now() / 1000;
const clock = new Date(t * 1000).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", second: "2-digit" });
const ago = now - t;
return `${clock} · ${ago < 3 ? "now" : fmt.dur(ago) + " ago"}`;
}
function drawHover(svg) {
const d = svg._data, tip = svg._tip, dot = svg._dot;
if (!tip) return;
const old = svg.querySelector(".guide");
if (old) old.remove();
const hide = () => { tip.style.display = "none"; dot.style.display = "none"; };
if (!d || svg._hoverVX == null || !d.pts.length) return hide();
// Samples are right-aligned: the newest sits at x = CW, one step per sample to the left.
const step = CW / (CN - 1);
let i = Math.round(d.pts.length - 1 - (CW - svg._hoverVX) / step);
if (i < 0) return hide();
i = Math.min(i, d.pts.length - 1);
// Snap to the nearest real sample if the cursor is over a gap (e.g. while a model loads).
if (d.pts[i] == null) {
let j = -1;
for (let k = 1; k <= 3 && j < 0; k++) {
if (d.pts[i - k] != null) j = i - k; else if (d.pts[i + k] != null) j = i + k;
}
if (j < 0) return hide();
i = j;
}
const v = d.pts[i], vx = d.x(i), vy = d.y(v);
svg.insertAdjacentHTML("beforeend",
`<line class="guide" x1="${vx}" x2="${vx}" y1="0" y2="${CH}" stroke="var(--faint)" stroke-dasharray="3 3" vector-effect="non-scaling-stroke" />`);
const r = svg.getBoundingClientRect();
const px = vx / CW * r.width, py = vy / CH * r.height;
Object.assign(dot.style, { display: "block", left: px + "px", top: py + "px", background: d.color });
tip.innerHTML = "";
tip.append(d.f(v), Object.assign(document.createElement("small"), { textContent: timeLabel(d.times[i]) }));
tip.style.display = "block";
const tw = tip.offsetWidth;
tip.style.left = Math.max(0, Math.min(r.width - tw, px - tw / 2)) + "px";
const above = py - tip.offsetHeight - 10;
tip.style.top = (above >= -24 ? above : py + 12) + "px";
}
document.querySelectorAll(".chart svg").forEach(attachHover);
async function switchTo(p) {
if (state && state.phase === "ready" && state.metrics && state.metrics.running > 0 &&
!confirm(`${state.metrics.running} request(s) are running on ${state.active}. Switch anyway?`)) return;
if (!p.downloaded && !confirm(`${p.name} isn't downloaded yet. Download ${p.weights_gib} GiB now and load it?`)) return;
try { await api("/api/switch", { method: "POST", body: JSON.stringify({ model: p.name }) }); toast(p.downloaded ? `Loading ${p.name}…` : `Downloading ${p.name}, then loading…`); poll(); }
catch (e) { toast("Switch failed: " + e.message); }
}
async function ctl(kind, confirmMsg) {
if (confirmMsg && !confirm(confirmMsg)) return;
try { await api("/api/" + kind, { method: "POST" }); poll(); } catch (e) { toast(kind + " failed: " + e.message); }
}
$("btn-stop").onclick = () => ctl("stop", "Stop the model server? This frees GPU memory; clients won't work until you start it again.");
$("btn-start").onclick = () => ctl("start");
$("btn-restart").onclick = () => ctl("restart", "Restart the model server? It takes a few minutes to come back.");
async function loadLogs() {
try { const r = await api("/api/logs"); const pre = $("log-text");
const atBottom = pre.scrollHeight - pre.scrollTop - pre.clientHeight < 30;
pre.textContent = r.lines.join("\n") || "(empty)";
if (atBottom) pre.scrollTop = pre.scrollHeight;
} catch (e) {}
}
$("logs").addEventListener("toggle", () => {
clearInterval(logTimer);
if ($("logs").open) { loadLogs(); logTimer = setInterval(loadLogs, 4000); }
});
let pollTimer = null;
async function poll() {
clearTimeout(pollTimer);
if (!KEY) { showAuth(); return; }
try { render(await api("/api/status")); }
catch (e) { if (e.message !== "unauthorized") { $("phase").textContent = "Dashboard unreachable"; $("phase").className = "pill failed"; } }
pollTimer = setTimeout(poll, 2000);
}
poll();
</script>
</body>
</html>