feat(local-llm): B0.5 — llama-swap + lokale Modellauswahl in Diagnostic
Mehrere lokale Modelle, on-demand geladen/geswappt, in Diagnostic waehlbar. Design: das Brain schickt den Modellnamen (aus local_llm.json) im llm_request mit -> Adapter -> llama-swap laedt/swappt. Keine separate Gamebox-Config noetig. - xtts: `llama`-Container -> `llama-swap` (unified-cuda), config.yaml mit qwen3-8b (Standard) + qwen3-4b; Auto-Download via -hf, Cache /models geteilt (qwen3-8b schon da). Adapter -> llama-swap:8080, Timeout 600s (Erst-Download). - adapter: `model` aus dem Request an llama-swap durchreichen (Fallback env). - brain: router.load_config liest localLlmModel; local_llm_chat(model=...); agent gibt cfg-Modell mit; bridge reicht model durch (_local_llm + Route). - diagnostic: /api/local-models-list (aus /shared/config/local_models.json, seeded), local-llm-config um localLlmModel erweitert; Dropdown "Lokales Modell" im Settings-Block + Erst-Download-Hinweis. BLIND gebaut (Gamebox nicht testbar hier): llama-swap CLI/Config-Pfad beim ersten Start via `docker logs aria-llama-swap` pruefen. Live-Lade-Status (Adapter->Diagnostic) ist B0.5-2 (Folgeschritt). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+49
-2
@@ -956,6 +956,21 @@
|
||||
<br><span style="color:#FFD60A;">Aktueller Stand (B1a): das lokale Modell <strong>plaudert nur</strong> — Werkzeuge macht noch Claude. Lokale Tools kommen mit B1b.</span>
|
||||
</div>
|
||||
|
||||
<!-- Lokales Modell (llama-swap, B0.5) -->
|
||||
<div style="display:flex;align-items:center;gap:8px;margin:12px 0 4px 0;padding-top:10px;border-top:1px solid #2a2a3a;">
|
||||
<span style="font-size:13px;color:#E0E0F0;"><strong>Lokales Modell:</strong></span>
|
||||
<select id="local-llm-model" onchange="saveLocalLlmConfig()" style="flex:1;background:#1E1E2E;border:1px solid #333;border-radius:4px;padding:6px 8px;color:#E0E0F0;font-family:inherit;font-size:12px;">
|
||||
<option value="">(lade Liste…)</option>
|
||||
</select>
|
||||
<button class="btn secondary" onclick="loadLocalModelList()" title="Liste neu laden" style="padding:4px 8px;font-size:10px;">↻</button>
|
||||
</div>
|
||||
<div id="local-llm-model-desc" style="font-size:10px;color:#8888AA;margin:0 0 2px 0;line-height:1.5;"></div>
|
||||
<div style="font-size:10px;color:#FFD60A;margin:0 0 4px 0;line-height:1.5;">
|
||||
Beim ersten Wechsel zu einem Modell lädt die Gamebox das GGUF (mehrere GB) —
|
||||
die <strong>erste Antwort dauert dann länger</strong>, danach ist es gecacht.
|
||||
Liste kommt aus <code>/shared/config/local_models.json</code> (Keys = xtts/llama-swap/config.yaml).
|
||||
</div>
|
||||
|
||||
<div id="local-llm-status" style="font-size:11px;color:#6a6a88;margin-top:8px;padding-top:8px;border-top:1px solid #2a2a3a;min-height:14px;"></div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1571,8 +1586,8 @@
|
||||
try { loadBrainStatus(); } catch {}
|
||||
// Sprachmodell-Dropdown befuellen (kuratierte Tier-Liste vom Proxy)
|
||||
try { loadModelList(); } catch {}
|
||||
// Lokales-LLM-Schalter aus /shared/config/local_llm.json laden
|
||||
try { loadLocalLlmConfig(); } catch {}
|
||||
// Lokales-LLM: erst Modell-Liste (Dropdown), dann Config (Auswahl setzen)
|
||||
try { loadLocalModelList().then(() => loadLocalLlmConfig()); } catch {}
|
||||
};
|
||||
|
||||
// Brain-Status periodisch refreshen damit die Card live bleibt
|
||||
@@ -6254,6 +6269,29 @@
|
||||
el.style.color = '#4ADE80';
|
||||
}
|
||||
}
|
||||
let _localModelsCache = [];
|
||||
let _currentLocalModel = 'qwen3-8b';
|
||||
function updateLocalModelDesc() {
|
||||
const el = document.getElementById('local-llm-model-desc');
|
||||
const sel = document.getElementById('local-llm-model');
|
||||
if (!el || !sel) return;
|
||||
const m = _localModelsCache.find(x => x.id === sel.value);
|
||||
el.textContent = m && m.description ? m.description : '';
|
||||
}
|
||||
async function loadLocalModelList() {
|
||||
try {
|
||||
const r = await fetch('/api/local-models-list');
|
||||
const j = await r.json();
|
||||
_localModelsCache = (j && j.models) || [];
|
||||
} catch (e) { _localModelsCache = []; }
|
||||
const sel = document.getElementById('local-llm-model');
|
||||
if (sel) {
|
||||
sel.innerHTML = _localModelsCache.map(m =>
|
||||
`<option value="${m.id}">${m.display_name || m.id}</option>`).join('') || '<option value="">(keine)</option>';
|
||||
if (_localModelsCache.some(m => m.id === _currentLocalModel)) sel.value = _currentLocalModel;
|
||||
updateLocalModelDesc();
|
||||
}
|
||||
}
|
||||
async function loadLocalLlmConfig() {
|
||||
try {
|
||||
const r = await fetch('/api/local-llm-config');
|
||||
@@ -6264,15 +6302,24 @@
|
||||
if (en) en.checked = !!c.enabled;
|
||||
if (ol) ol.checked = !!c.localOnly;
|
||||
if (tv) tv.value = (c.toolVariant === 'full') ? 'full' : 'slim';
|
||||
_currentLocalModel = c.localLlmModel || 'qwen3-8b';
|
||||
const sel = document.getElementById('local-llm-model');
|
||||
if (sel && _localModelsCache.some(m => m.id === _currentLocalModel)) {
|
||||
sel.value = _currentLocalModel;
|
||||
updateLocalModelDesc();
|
||||
}
|
||||
setLocalLlmStatus(c);
|
||||
} catch (e) { /* still */ }
|
||||
}
|
||||
async function saveLocalLlmConfig() {
|
||||
const modelSel = document.getElementById('local-llm-model');
|
||||
const body = {
|
||||
enabled: document.getElementById('local-llm-enabled').checked,
|
||||
localOnly: document.getElementById('local-llm-onlylocal').checked,
|
||||
toolVariant: document.getElementById('local-llm-toolvariant').value,
|
||||
localLlmModel: (modelSel && modelSel.value) || '',
|
||||
};
|
||||
updateLocalModelDesc();
|
||||
try {
|
||||
const r = await fetch('/api/local-llm-config', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
|
||||
+27
-1
@@ -309,9 +309,10 @@ function readLocalLlmConfig() {
|
||||
enabled: !!p.enabled,
|
||||
localOnly: !!p.localOnly,
|
||||
toolVariant: p.toolVariant === "full" ? "full" : "slim",
|
||||
localLlmModel: (typeof p.localLlmModel === "string" && p.localLlmModel) ? p.localLlmModel : "qwen3-8b",
|
||||
};
|
||||
} catch {
|
||||
return { enabled: false, localOnly: false, toolVariant: "slim" };
|
||||
return { enabled: false, localOnly: false, toolVariant: "slim", localLlmModel: "qwen3-8b" };
|
||||
}
|
||||
}
|
||||
function writeLocalLlmConfig(patch) {
|
||||
@@ -319,6 +320,7 @@ function writeLocalLlmConfig(patch) {
|
||||
if (typeof patch.enabled === "boolean") cur.enabled = patch.enabled;
|
||||
if (typeof patch.localOnly === "boolean") cur.localOnly = patch.localOnly;
|
||||
if (patch.toolVariant === "slim" || patch.toolVariant === "full") cur.toolVariant = patch.toolVariant;
|
||||
if (typeof patch.localLlmModel === "string" && patch.localLlmModel.trim()) cur.localLlmModel = patch.localLlmModel.trim();
|
||||
fs.mkdirSync("/shared/config", { recursive: true });
|
||||
const tmp = LOCAL_LLM_CONFIG_FILE + ".tmp";
|
||||
fs.writeFileSync(tmp, JSON.stringify(cur, null, 2));
|
||||
@@ -326,6 +328,27 @@ function writeLocalLlmConfig(patch) {
|
||||
return cur;
|
||||
}
|
||||
|
||||
// ── Lokale Modell-Liste (Diagnostic-Dropdown) ────────────────
|
||||
// /shared/config/local_models.json — kuratierte Liste; muss zu den KEYS in
|
||||
// xtts/llama-swap/config.yaml passen. Wird bei Bedarf mit Defaults seeded.
|
||||
const LOCAL_MODELS_FILE = "/shared/config/local_models.json";
|
||||
const DEFAULT_LOCAL_MODELS = [
|
||||
{ id: "qwen3-8b", display_name: "Qwen3 8B (Standard)", description: "Bestes Tool-Calling, ~6 GB. Passt auf 12 GB." },
|
||||
{ id: "qwen3-4b", display_name: "Qwen3 4B (schneller)", description: "Kleiner + flotter, ~3 GB. Etwas schwaecher." },
|
||||
];
|
||||
function loadLocalModels() {
|
||||
try {
|
||||
const arr = JSON.parse(fs.readFileSync(LOCAL_MODELS_FILE, "utf-8"));
|
||||
if (Array.isArray(arr) && arr.length && arr.every(m => m && typeof m.id === "string")) return arr;
|
||||
} catch {}
|
||||
// Seed defaults
|
||||
try {
|
||||
fs.mkdirSync("/shared/config", { recursive: true });
|
||||
fs.writeFileSync(LOCAL_MODELS_FILE, JSON.stringify(DEFAULT_LOCAL_MODELS, null, 2));
|
||||
} catch {}
|
||||
return DEFAULT_LOCAL_MODELS;
|
||||
}
|
||||
|
||||
// ── File-Project-Manifest ───────────────────────────────────────────
|
||||
// Jeder Eintrag map[absoluter_pfad] = project_id (leer = Hauptchat).
|
||||
// Wird vom files-list-Endpoint + files-set-project gepflegt.
|
||||
@@ -1602,6 +1625,9 @@ const server = http.createServer((req, res) => {
|
||||
}
|
||||
});
|
||||
return;
|
||||
} else if (req.url === "/api/local-models-list" && req.method === "GET") {
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify({ ok: true, models: loadLocalModels() }));
|
||||
} else if (req.url === "/api/local-llm-config" && req.method === "GET") {
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify(readLocalLlmConfig()));
|
||||
|
||||
Reference in New Issue
Block a user