jean-router: contexte reel depuis llama-server + overrides
- Interroge llama-server:8080 pour le n_ctx du modele actif - JEAN_CTX_OVERRIDES prioritaire si defini - Fallback: Ollama matching → heuristique - Plus de devinette, le contexte est precis
This commit is contained in:
+28
-6
@@ -38,6 +38,7 @@ ENABLE_WOL = os.getenv("ENABLE_WOL", "false").lower() == "true"
|
||||
TARGET_MAC = os.getenv("TARGET_MAC", os.getenv("PC_GAMING_MAC", ""))
|
||||
BROADCAST_IP = os.getenv("BROADCAST_IP", "192.168.1.255")
|
||||
WAKE_TIMEOUT = int(os.getenv("WAKE_TIMEOUT", "180"))
|
||||
JEAN_CTX_OVERRIDES = json_mod.loads(os.getenv("JEAN_CTX_OVERRIDES", "{}"))
|
||||
wol_in_progress = threading.Lock()
|
||||
jean_alive_cache = {"alive": False, "timestamp": 0}
|
||||
|
||||
@@ -469,9 +470,29 @@ def _match_preset_to_ollama(preset_id: str):
|
||||
|
||||
def get_jean_metadata():
|
||||
"""Resout dynamiquement context_length et capabilities pour les presets Jean.
|
||||
1) Ollama matching → 2) Jean /v1/models → 3) heuristique"""
|
||||
now = time.time()
|
||||
1) JEAN_CTX_OVERRIDES → 2) llama-server /v1/models → 3) Ollama matching → 4) heuristique"""
|
||||
|
||||
# 1 — Overrides utilisateur (priorite max)
|
||||
for pid, ctx in JEAN_CTX_OVERRIDES.items():
|
||||
jean_ctx_cache[pid] = ctx
|
||||
|
||||
# 2 — llama-server direct (port 8080, modele actif)
|
||||
try:
|
||||
r = requests.get(f"http://{JEAN_WEB_HOST}:8080/v1/models", timeout=3)
|
||||
if r.ok:
|
||||
for m in r.json().get("data", []):
|
||||
meta = m.get("meta", {})
|
||||
ctx = meta.get("n_ctx") or m.get("max_model_len") or m.get("context_length")
|
||||
if ctx:
|
||||
# Associer ce ctx au preset actif (meme nom ou alias)
|
||||
active = get_active_preset()
|
||||
if active:
|
||||
jean_ctx_cache[active["id"]] = int(ctx)
|
||||
log.info(f"[Jean] ctx reel via llama-server: {active['id']}={ctx}")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 3 — Jean proxy /v1/models (via jean-proxy, pour le modele actif)
|
||||
try:
|
||||
url = f"http://{JEAN_PROXY_HOST}:{JEAN_PROXY_PORT}/v1/models"
|
||||
r = requests.get(url, timeout=2)
|
||||
@@ -480,7 +501,7 @@ def get_jean_metadata():
|
||||
alias = m.get("id", "")
|
||||
meta = m.get("meta", {})
|
||||
n_ctx = meta.get("n_ctx") or m.get("max_model_len")
|
||||
if n_ctx and alias:
|
||||
if n_ctx and alias and alias not in jean_ctx_cache:
|
||||
jean_ctx_cache[alias] = int(n_ctx)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -503,7 +524,9 @@ def get_jean_metadata():
|
||||
ollama_name = matched_ollama.get("name", "").replace(":latest", "") if matched_ollama else None
|
||||
|
||||
if pid not in jean_ctx_cache:
|
||||
if ollama_name and ollama_lookup.get(ollama_name, {}).get("context_length"):
|
||||
if pid in JEAN_CTX_OVERRIDES:
|
||||
jean_ctx_cache[pid] = JEAN_CTX_OVERRIDES[pid]
|
||||
elif ollama_name and ollama_lookup.get(ollama_name, {}).get("context_length"):
|
||||
jean_ctx_cache[pid] = ollama_lookup[ollama_name]["context_length"]
|
||||
else:
|
||||
jean_ctx_cache[pid] = _guess_context_length(pid)
|
||||
@@ -1202,9 +1225,8 @@ h1{font-size:18px;color:var(--purple);margin-bottom:12px}
|
||||
</div>
|
||||
<div class="card">
|
||||
<h2>⚡ Actions</h2>
|
||||
<button class="btn" onclick="action('refresh')">🔄 Refresh cache</button>
|
||||
<button class="btn" onclick="action('refresh');setTimeout(fetchStatus,800)">🔄 Actualiser modèles Jean + Ollama</button>
|
||||
<button class="btn btn-danger" onclick="action('restart-jean')" title="Stop + Start Jean">🔁 Restart Jean</button>
|
||||
<button class="btn" onclick="location.reload()">↻ Reload page</button>
|
||||
<div style="margin-top:8px">
|
||||
<span class="badge badge-blue" id="wol-badge">WoL: -</span>
|
||||
<span class="badge badge-green" id="cache-badge">Cache: -</span>
|
||||
|
||||
Reference in New Issue
Block a user