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
+20 -24
View File
@@ -90,22 +90,19 @@ services:
# Container-Restarts.
restart: unless-stopped
# ─── Lokales LLM (Plan B, B0) — llama.cpp-Server (GPU) ────────
# Serviert Qwen3-8B (GGUF Q4_K_M) OpenAI-kompatibel auf :8081, NUR im
# Compose-Netz (kein RVS direkt) — die Bruecke macht der llm-adapter.
# ─── Lokales LLM (Plan B, B0.5) — llama-swap (GPU) ────────────
# llama-swap laedt/swappt mehrere Modelle on-demand (nur eins passt gleich-
# zeitig in die 12 GB). Welches geladen wird, bestimmt das `model`-Feld im
# Request — das Brain schickt es aus local_llm.json mit. Erster Load eines
# Modells zieht das GGUF via -hf von HF (Cache unter /models, persistent).
# OpenAI-kompatibel auf :8080, nur im Compose-Netz; die Bruecke macht der
# llm-adapter. Modell-Liste: ./llama-swap/config.yaml.
#
# AUTO-DOWNLOAD: llama.cpp zieht das GGUF beim ersten Start selbst von
# Hugging Face (-hf <repo>:<quant>) und cached es unter /models (persistent
# via Bind-Mount -> kein Re-Download bei Restart). Kein manuelles Ablegen
# noetig. Modell wechseln = LLM_HF_REPO/LLM_HF_QUANT in der .env aendern +
# Container neu. (Alternativ lokale Datei: command auf -m /models/x.gguf.)
#
# VRAM auf der RTX 3060 (12 GB): whisper-small (~1-2) + f5tts (~1-2) +
# qwen3-8b-q4 (~6) ~= 9-10 GB. Passt, aber knapp — bei OOM: LLM_CTX kleiner
# oder Quant auf Q4_K_S/IQ4_XS wechseln.
llama:
image: ghcr.io/ggml-org/llama.cpp:server-cuda
container_name: aria-llama
# BLIND GEBAUT (kein Gamebox-Test hier): beim ersten Start
# `docker logs -f aria-llama-swap` pruefen. Image bundelt llama-server.
llama-swap:
image: ghcr.io/mostlygeek/llama-swap:unified-cuda
container_name: aria-llama-swap
deploy:
resources:
reservations:
@@ -114,13 +111,11 @@ services:
count: 1
capabilities: [gpu]
volumes:
- ./models:/models # HF-Download-Cache (persistent)
- ./models:/models # HF-Download-Cache (persistent)
- ./llama-swap/config.yaml:/app/config.yaml:ro # Modell-Liste
environment:
- LLAMA_CACHE=/models # llama.cpp legt -hf-Downloads hier ab
command: >
-hf ${LLM_HF_REPO:-Qwen/Qwen3-8B-GGUF}:${LLM_HF_QUANT:-Q4_K_M}
--host 0.0.0.0 --port 8081
-ngl 99 -c ${LLM_CTX:-8192} --jinja
- LLAMA_CACHE=/models # llama-server legt -hf-Downloads hier ab
command: ["--config", "/app/config.yaml", "--listen", "0.0.0.0:8080"]
restart: unless-stopped
# ─── Local-LLM-Adapter — RVS <-> llama.cpp (Plan B, B0) ──────
@@ -130,14 +125,15 @@ services:
build: ./llm-adapter
container_name: aria-llm-adapter
depends_on:
- llama
- llama-swap
environment:
- RVS_HOST=${RVS_HOST}
- RVS_PORT=${RVS_PORT:-443}
- RVS_TLS=${RVS_TLS:-true}
- RVS_TLS_FALLBACK=${RVS_TLS_FALLBACK:-true}
- RVS_TOKEN=${RVS_TOKEN}
- LLAMA_URL=http://llama:8081
- LLAMA_URL=http://llama-swap:8080
- LLM_MODEL=${LLM_MODEL:-qwen3-8b}
- LLM_TIMEOUT_SEC=${LLM_TIMEOUT_SEC:-60}
# Erster Load eines Modells kann ein GGUF ziehen (mehrere GB) — grosszuegig.
- LLM_TIMEOUT_SEC=${LLM_TIMEOUT_SEC:-600}
restart: unless-stopped
+42
View File
@@ -0,0 +1,42 @@
# llama-swap Modell-Liste fuer ARIA (Plan B, B0.5).
# Welches Modell geladen wird, bestimmt das `model`-Feld im Request (das Brain
# schickt es aus /shared/config/local_llm.json mit). llama-swap laedt es
# on-demand, swappt bei Bedarf (nur eins passt gleichzeitig in die 12 GB).
# Erster Load zieht das GGUF via -hf von Hugging Face (Cache unter /models).
#
# Die Modell-KEYS hier muessen zu local_models.json (Diagnostic-Dropdown) passen.
#
# healthCheckTimeout: Sekunden, die llama-swap auf "Modell bereit" wartet.
# GROSSZUEGIG, weil der erste Load ein GGUF (mehrere GB) herunterlaedt. Wenn der
# erste Download laenger dauert und abbricht: hier hochsetzen.
healthCheckTimeout: 1800
models:
# Standard — Qwen3 8B (~6 GB Q4). Bestes Tool-Calling, passt auf 12 GB.
"qwen3-8b":
cmd: |
llama-server --port ${PORT} --host 127.0.0.1
-hf Qwen/Qwen3-8B-GGUF:Q4_K_M
-ngl 99 -c 8192 --jinja
ttl: 3600 # nach 1h Idle entladen (VRAM freigeben)
# Kleiner + schneller — Qwen3 4B (~3 GB). Fuer noch flottere Antworten,
# etwas schwaecher. Guter A/B-Vergleich gegen 8B.
"qwen3-4b":
cmd: |
llama-server --port ${PORT} --host 127.0.0.1
-hf Qwen/Qwen3-4B-GGUF:Q4_K_M
-ngl 99 -c 8192 --jinja
ttl: 3600
# ── Vorlagen fuer spaeter (auskommentiert; brauchen mehr VRAM / 2. Karte) ──
# "qwen3-14b":
# cmd: |
# llama-server --port ${PORT} --host 127.0.0.1
# -hf Qwen/Qwen3-14B-GGUF:Q4_K_M -ngl 99 -c 8192 --jinja
# ttl: 3600
# "mistral-small-3":
# cmd: |
# llama-server --port ${PORT} --host 127.0.0.1
# -hf <mistral-small-3-gguf-repo>:Q4_K_M -ngl 99 -c 8192 --jinja
# ttl: 3600
+13 -9
View File
@@ -69,14 +69,16 @@ async def _send(ws, mtype: str, payload: dict) -> None:
async def _call_llama(messages: list, *, max_tokens: int, temperature: float,
stop, tools=None) -> dict:
"""Ruft llama.cpp /v1/chat/completions (OpenAI-Format). Gibt
stop, tools=None, model=None) -> dict:
"""Ruft llama.cpp/llama-swap /v1/chat/completions (OpenAI-Format). Gibt
{ok, content, tool_calls, error} zurueck — wirft nie.
tools: optionale OpenAI-Tool-Definitionen (B1b). llama.cpp (--jinja) mit
Qwen3 kann natives Tool-Calling und liefert dann message.tool_calls."""
model: welches Modell llama-swap laden soll (B0.5). Kommt aus dem Request
(Brain -> local_llm.json). Faellt auf LLM_MODEL (env) zurueck.
tools: optionale OpenAI-Tool-Definitionen (B1b). Qwen3 (--jinja) kann
natives Tool-Calling und liefert dann message.tool_calls."""
body = {
"model": LLM_MODEL,
"model": model or LLM_MODEL,
"messages": messages,
"max_tokens": max_tokens,
"temperature": temperature,
@@ -120,13 +122,15 @@ async def _handle_llm_request(ws, payload: dict) -> None:
temperature = float(payload.get("temperature", 0.7) or 0.7)
stop = payload.get("stop")
tools = payload.get("tools") or None
model = (payload.get("model") or "").strip() or None
t0 = time.time()
res = await _call_llama(messages, max_tokens=max_tokens,
temperature=temperature, stop=stop, tools=tools)
temperature=temperature, stop=stop, tools=tools,
model=model)
dt = time.time() - t0
tc = res.get("tool_calls")
logger.info("llm_request id=%s -> ok=%s %.2fs content_len=%d tool_calls=%d",
(req_id[:8] if req_id else "?"), res.get("ok"), dt,
logger.info("llm_request id=%s model=%s -> ok=%s %.2fs content_len=%d tool_calls=%d",
(req_id[:8] if req_id else "?"), model or LLM_MODEL, res.get("ok"), dt,
len(res.get("content") or ""), len(tc) if tc else 0)
await _send(ws, "llm_response", {
"requestId": req_id,
@@ -134,7 +138,7 @@ async def _handle_llm_request(ws, payload: dict) -> None:
"content": res.get("content", ""),
"tool_calls": tc,
"error": res.get("error"),
"model": LLM_MODEL,
"model": model or LLM_MODEL,
"elapsedMs": int(dt * 1000),
})