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:
2026-07-11 14:11:59 +02:00
co-authored by Claude Opus 4.8
parent 3ddcf665f0
commit 8ae20a9bd8
9 changed files with 174 additions and 46 deletions
+27 -1
View File
@@ -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()));