localdeploy 0.6.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. api_server.py +15 -0
  2. benchmark.py +15 -0
  3. chat_cli.py +15 -0
  4. compare_models.py +15 -0
  5. localdeploy/__init__.py +3 -0
  6. localdeploy/backends/__init__.py +0 -0
  7. localdeploy/backends/llamacpp.py +143 -0
  8. localdeploy/backends/ollama.py +374 -0
  9. localdeploy/backends/openai_compatible.py +179 -0
  10. localdeploy/benchmark.py +1996 -0
  11. localdeploy/chat_cli.py +249 -0
  12. localdeploy/cli.py +59 -0
  13. localdeploy/compare_models.py +481 -0
  14. localdeploy/control/__init__.py +75 -0
  15. localdeploy/control/_config.py +180 -0
  16. localdeploy/control/_ollama.py +253 -0
  17. localdeploy/control/bakeoff.py +216 -0
  18. localdeploy/control/bench.py +516 -0
  19. localdeploy/control/calibration.py +191 -0
  20. localdeploy/control/community.py +161 -0
  21. localdeploy/control/fit.py +651 -0
  22. localdeploy/control/hardware.py +602 -0
  23. localdeploy/control/history.py +125 -0
  24. localdeploy/control/manifest.py +452 -0
  25. localdeploy/control/models.py +833 -0
  26. localdeploy/control/monitor.py +378 -0
  27. localdeploy/control/profiles.py +161 -0
  28. localdeploy/control/recommend.py +322 -0
  29. localdeploy/control/registry.py +956 -0
  30. localdeploy/control/report.py +407 -0
  31. localdeploy/control/starter.py +520 -0
  32. localdeploy/control/updates.py +118 -0
  33. localdeploy/grader_sandbox.py +268 -0
  34. localdeploy/server.py +1873 -0
  35. localdeploy/utils.py +155 -0
  36. localdeploy/web/favicon.png +0 -0
  37. localdeploy/web/index.html +891 -0
  38. localdeploy/web/js/app.js +63 -0
  39. localdeploy/web/js/benchmark-views.js +73 -0
  40. localdeploy/web/js/benchmark.js +1691 -0
  41. localdeploy/web/js/chat.js +779 -0
  42. localdeploy/web/js/models.js +2758 -0
  43. localdeploy/web/js/shared.js +454 -0
  44. localdeploy/web/js/system.js +626 -0
  45. localdeploy/web/logo.svg +22 -0
  46. localdeploy/web/styles.css +2032 -0
  47. localdeploy-0.6.0.dist-info/METADATA +202 -0
  48. localdeploy-0.6.0.dist-info/RECORD +52 -0
  49. localdeploy-0.6.0.dist-info/WHEEL +5 -0
  50. localdeploy-0.6.0.dist-info/entry_points.txt +2 -0
  51. localdeploy-0.6.0.dist-info/licenses/LICENSE +21 -0
  52. localdeploy-0.6.0.dist-info/top_level.txt +5 -0
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ import { $, $$, initSharedUI, toast } from "./shared.js?v=20260719-ui32";
4
+ import { getSystemSnapshot, initSystem, refreshOllamaStatus, refreshSystem, setMonitorActive, subscribeToSystemChanges, updateModelContext as updateSystemModelContext } from "./system.js?v=20260719-ui32";
5
+ import { getModelSnapshot, initModels, refreshModels, setDefaultProfile, subscribeToModelChanges, updateSystemContext as updateModelsSystemContext } from "./models.js?v=20260719-ui32";
6
+ import { initChat, updateModelContext as updateChatModelContext } from "./chat.js?v=20260719-ui32";
7
+ import { initBenchmark, refreshBenchmarkMetadata, updateModelContext as updateBenchmarkModelContext, updateSystemContext as updateBenchmarkSystemContext } from "./benchmark.js?v=20260719-ui32";
8
+
9
+ function propagateSystem(snapshot = getSystemSnapshot()) {
10
+ updateModelsSystemContext(snapshot);
11
+ updateBenchmarkSystemContext(snapshot);
12
+ }
13
+
14
+ function propagateModels(snapshot = getModelSnapshot()) {
15
+ updateChatModelContext(snapshot);
16
+ updateBenchmarkModelContext(snapshot);
17
+ updateSystemModelContext({ installedCount: snapshot.installed.length, running: snapshot.running });
18
+ }
19
+
20
+ async function invalidateModelState() {
21
+ await Promise.allSettled([refreshModels(), refreshOllamaStatus()]);
22
+ propagateSystem(); propagateModels();
23
+ }
24
+
25
+ function initializeFeature(label, initializer) {
26
+ try {
27
+ initializer();
28
+ return { status: "fulfilled", label };
29
+ } catch (error) {
30
+ console.error(`LocalDeploy ${label} initialization failed`, error);
31
+ toast(`${label} failed to initialize: ${error.message}`, "error");
32
+ return { status: "rejected", label, reason: error };
33
+ }
34
+ }
35
+
36
+ function activateTab(name) {
37
+ $$(".tab").forEach((tab) => { const active = tab.dataset.tab === name; tab.classList.toggle("active", active); tab.setAttribute("aria-selected", active ? "true" : "false"); });
38
+ $$(".tab-panel").forEach((panel) => panel.classList.toggle("active", panel.id === `tab-${name}`));
39
+ setMonitorActive(name === "monitor");
40
+ if (name === "serve") void invalidateModelState();
41
+ else if (name === "bench") void refreshModels({ profiles: false, installed: false });
42
+ else if (name === "chat") void invalidateModelState().then(() => $("#chat-input")?.focus());
43
+ }
44
+
45
+ async function bootstrap() {
46
+ initializeFeature("shared UI", initSharedUI);
47
+ subscribeToSystemChanges(propagateSystem);
48
+ subscribeToModelChanges((snapshot, meta) => { propagateModels(snapshot); if (meta?.requiresSystemRefresh) void refreshSystem(); });
49
+ initializeFeature("system", () => initSystem({ onNavigate: activateTab, onModelStateInvalidated: invalidateModelState }));
50
+ initializeFeature("models", initModels);
51
+ initializeFeature("chat", () => initChat({ onModelStateInvalidated: invalidateModelState, onNavigate: activateTab }));
52
+ initializeFeature("benchmark", () => initBenchmark({ onModelStateInvalidated: invalidateModelState, setDefaultProfile }));
53
+ $$(".tab").forEach((tab) => tab.addEventListener("click", () => activateTab(tab.dataset.tab)));
54
+ $("#brand-home")?.addEventListener("click", () => activateTab("serve"));
55
+ const results = await Promise.allSettled([refreshSystem(), refreshModels(), refreshBenchmarkMetadata()]);
56
+ propagateSystem(); propagateModels();
57
+ results.filter((result) => result.status === "rejected").forEach((result) => console.error("LocalDeploy startup task failed", result.reason));
58
+ }
59
+
60
+ bootstrap().catch((error) => {
61
+ console.error("LocalDeploy startup failed", error);
62
+ toast(`LocalDeploy startup failed: ${error.message}`, "error");
63
+ });
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ import { esc } from "./shared.js?v=20260719-ui32";
4
+
5
+ function runLabel(run) { return [run.profile || run.modelId || "run", run.actualDevice || run.requestedDevice].filter(Boolean).join(" · "); }
6
+ function categorySummary(tests = []) {
7
+ const groups = new Map();
8
+ tests.forEach((test) => { const key = test.category || "?"; const row = groups.get(key) || []; row.push(test); groups.set(key, row); });
9
+ return [...groups].map(([category, rows]) => ({ category, avg_accuracy: rows.reduce((sum, row) => sum + Number(row.accuracy || 0), 0) / Math.max(rows.length, 1) }));
10
+ }
11
+ function heatColor(accuracy) { const value = Math.max(0, Math.min(1, Number(accuracy || 0))); return value >= 0.8 ? "heat-good" : value >= 0.5 ? "heat-warn" : "heat-bad"; }
12
+
13
+ export function renderWinners(runs) {
14
+ if (!runs.length) return "";
15
+ const ranked = [...runs].sort((a, b) => (b.summary.passed || 0) - (a.summary.passed || 0) || (b.summary.avg_accuracy || 0) - (a.summary.avg_accuracy || 0) || (a.summary.avg_latency_s || 999999) - (b.summary.avg_latency_s || 999999));
16
+ const top = ranked[0];
17
+ const fastest = [...runs].filter((run) => run.summary.avg_latency_s != null).sort((a, b) => a.summary.avg_latency_s - b.summary.avg_latency_s)[0];
18
+ const bestTps = [...runs].filter((run) => run.summary.avg_tokens_per_second != null).sort((a, b) => b.summary.avg_tokens_per_second - a.summary.avg_tokens_per_second)[0];
19
+ const categories = new Set(runs.flatMap((run) => (run.category_summary || categorySummary(run.tests)).map((row) => row.category)));
20
+ return [
21
+ `<div class="metric-tile"><span>Top run</span><strong>${esc(runLabel(top))}</strong><small>${esc(top.summary.passed)}/${esc(top.summary.tests)} passed</small></div>`,
22
+ `<div class="metric-tile"><span>Accuracy</span><strong>${esc(top.summary.avg_accuracy)}</strong><small>${esc(top.questionSetName || "benchmark")}</small></div>`,
23
+ fastest ? `<div class="metric-tile"><span>Fastest</span><strong>${esc(fastest.summary.avg_latency_s)}s</strong><small>${esc(runLabel(fastest))}</small></div>` : "",
24
+ bestTps ? `<div class="metric-tile"><span>Best tok/s</span><strong>${esc(bestTps.summary.avg_tokens_per_second)}</strong><small>${esc(runLabel(bestTps))}</small></div>` : "",
25
+ `<div class="metric-tile"><span>Categories</span><strong>${esc(categories.size)}</strong><small>${esc(runs.length)} run${runs.length === 1 ? "" : "s"}</small></div>`,
26
+ ].join("");
27
+ }
28
+
29
+ export function renderLeaderboard(runs) {
30
+ if (!runs.length) return "Benchmark results appear here after the first streamed test result.";
31
+ const rows = [...runs].sort((a, b) => (b.summary.passed || 0) - (a.summary.passed || 0) || (b.summary.avg_accuracy || 0) - (a.summary.avg_accuracy || 0) || (a.summary.avg_latency_s || 999999) - (b.summary.avg_latency_s || 999999)).map((run, index) => `<div class="leaderboard-row"><span class="rank">${index + 1}</span><div class="leaderboard-name"><b>${esc(runLabel(run))}</b><span>${esc(run.questionSetName || "")}</span></div><div class="leaderboard-metrics"><span><b>${esc(run.summary.passed)}/${esc(run.summary.tests)}</b> passed</span><span><b>${esc(run.summary.avg_accuracy)}</b> acc</span><span><b>${esc(run.summary.avg_latency_s)}s</b> latency</span><span><b>${esc(run.summary.avg_tokens_per_second ?? "-")}</b> tok/s</span></div></div>`).join("");
32
+ return `<div class="leaderboard-list">${rows}</div>`;
33
+ }
34
+
35
+ export function renderHeatmap(runs) {
36
+ if (!runs.length) return "Run benchmarks to fill the category heatmap.";
37
+ const categories = Array.from(new Set(runs.flatMap((run) => (run.category_summary || categorySummary(run.tests)).map((row) => row.category)))).sort();
38
+ const columns = `minmax(140px, 180px) repeat(${runs.length}, minmax(120px, 160px))`;
39
+ const cells = categories.map((category) => `<div class="heat-category">${esc(category)}</div>${runs.map((run) => { const row = (run.category_summary || categorySummary(run.tests)).find((item) => item.category === category); const accuracy = row?.avg_accuracy ?? null; return `<div class="heat-cell ${accuracy == null ? "" : heatColor(accuracy)}" title="${esc(runLabel(run))} · ${esc(category)}">${accuracy == null ? "-" : Number(accuracy).toFixed(2)}</div>`; }).join("")}`).join("");
40
+ return `<div class="heatmap-scroll"><div class="heatmap-grid" style="grid-template-columns:${columns}"><div class="heat-head">Category</div>${runs.map((run) => `<div class="heat-head">${esc(runLabel(run))}</div>`).join("")}${cells}</div></div>`;
41
+ }
42
+
43
+ export function renderScatter(runs) {
44
+ const points = runs.filter((run) => run.summary.avg_latency_s != null && run.summary.avg_accuracy != null);
45
+ if (!points.length) return "Run at least one benchmark to plot speed and quality.";
46
+ if (points.length < 2) { const run = points[0]; return `<div class="scatter-single"><span class="eyebrow">One run captured</span><strong>${esc(run.summary.avg_accuracy)} accuracy</strong><span>${esc(run.summary.avg_latency_s)}s latency · ${esc(run.summary.avg_tokens_per_second ?? "-")} tok/s</span><small>Run another model or device to compare speed vs quality.</small></div>`; }
47
+ const maxLatency = Math.max(...points.map((run) => Number(run.summary.avg_latency_s || 0)), 1);
48
+ const labels = points.map((run, index) => { const x = 46 + (Number(run.summary.avg_latency_s || 0) / maxLatency) * 260; const y = 170 - Number(run.summary.avg_accuracy || 0) * 125; return `<g><circle cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" r="6" /><text x="${(x + 10).toFixed(1)}" y="${(y + 4).toFixed(1)}">${esc(String(index + 1))}</text><title>${esc(runLabel(run))}: ${esc(run.summary.avg_latency_s)}s, acc ${esc(run.summary.avg_accuracy)}</title></g>`; }).join("");
49
+ return `<svg class="scatter" viewBox="0 0 340 205" role="img" aria-label="Speed quality scatter"><line x1="40" y1="180" x2="316" y2="180"></line><line x1="40" y1="34" x2="40" y2="180"></line><line class="gridline" x1="40" y1="96" x2="316" y2="96"></line><text x="118" y="199">avg latency, lower is better</text><text x="8" y="28">accuracy</text>${labels}</svg>`;
50
+ }
51
+
52
+ export function renderMatrix(runs) {
53
+ if (!runs.length) return "Run benchmarks to fill the pass/fail matrix.";
54
+ const tests = Array.from(new Set(runs.flatMap((run) => (run.tests || []).map((test) => test.name)))).sort(); const maxRows = 80;
55
+ const rows = tests.slice(0, maxRows).map((name) => `<tr><th>${esc(name)}</th>${runs.map((run) => { const test = (run.tests || []).find((item) => item.name === name); const className = !test ? "" : test.success ? "matrix-pass" : "matrix-fail"; return `<td><span class="matrix-pill ${className}">${test ? `${test.success ? "PASS" : "FAIL"} · ${Number(test.accuracy || 0).toFixed(2)}` : "-"}</span></td>`; }).join("")}</tr>`).join("");
56
+ const note = tests.length > maxRows ? `<div class="muted small matrix-note">Showing first ${maxRows} of ${tests.length} tests. Use Detailed results for filters.</div>` : "";
57
+ return `<div class="table-wrap matrix-wrap"><table class="results matrix"><thead><tr><th>Test</th>${runs.map((run) => `<th>${esc(runLabel(run))}</th>`).join("")}</tr></thead><tbody>${rows}</tbody></table></div>${note}`;
58
+ }
59
+
60
+ export function renderResponseComparison({ testName, runs }) {
61
+ return `<div class="card-head"><h3 class="sub">Responses: ${esc(testName)}</h3><button class="btn compact" id="close-response-drawer">Close</button></div>
62
+ <div class="response-compare-grid">${runs.map((run) => {
63
+ const test = (run.tests || []).find((item) => item.name === testName);
64
+ const detail = test
65
+ ? `${test.success ? "PASS" : "FAIL"} · acc ${test.accuracy} · ${test.elapsed_seconds}s`
66
+ : "No result for this run";
67
+ return `<div class="response-compare-card">
68
+ <b>${esc(runLabel(run))}</b>
69
+ <div class="muted small">${esc(detail)}</div>
70
+ <pre>${esc(test?.response_preview || test?.error || "(no response preview)")}</pre>
71
+ </div>`;
72
+ }).join("")}</div>`;
73
+ }