diff --git a/jean-router/app.py b/jean-router/app.py index 4e522c8..928a30b 100644 --- a/jean-router/app.py +++ b/jean-router/app.py @@ -38,6 +38,7 @@ app = Flask(__name__) presets_cache = {"data": [], "timestamp": 0} ollama_cache = {"data": [], "timestamp": 0} +jean_ctx_cache = {} CACHE_TTL = 30 switch_lock = threading.Lock() vram_lock = threading.Lock() @@ -73,6 +74,38 @@ def get_ollama_models(force_refresh=False): if not force_refresh and ollama_cache["data"] and (now - ollama_cache["timestamp"]) < CACHE_TTL: return ollama_cache["data"] + +def get_jean_context_lengths(): + """Récupère les context_length depuis Jean /v1/models (avec cache)""" + preset_ctx_map = { + "ornith-35b-q6": 64000, + "qwen3.6-27b-mtp": 55000, + "qwen3.6-35b-moe-compact": 131072, + "qwen3.6-35b-moe-compact-reason": 131072, + "qwen3.6-35b-moe-nano": 100000, + } + + try: + url = f"http://{JEAN_PROXY_HOST}:{JEAN_PROXY_PORT}/v1/models" + r = requests.get(url, timeout=2) + if r.ok: + models = r.json().get("data", []) + for m in models: + meta = m.get("meta", {}) + n_ctx = meta.get("n_ctx") + if n_ctx: + alias = m.get("id", "") + jean_ctx_cache[alias] = n_ctx + log.debug(f"[Jean] Context length pour {alias}: {n_ctx}") + except Exception as e: + log.debug(f"[Jean] Impossible de récupérer context_length: {e}") + + for preset_id, ctx in preset_ctx_map.items(): + if preset_id not in jean_ctx_cache: + jean_ctx_cache[preset_id] = ctx + + return jean_ctx_cache + try: url = f"http://{OLLAMA_PROXY_HOST}:{OLLAMA_PROXY_PORT}/api/tags" r = requests.get(url, timeout=3) @@ -316,6 +349,7 @@ def ensure_vram_for_backend(target_backend: str) -> bool: def list_models(): """Expose tous les presets Jean + modèles Ollama comme modèles OpenAI""" presets = get_presets() + jean_ctx = get_jean_context_lengths() models = [] for p in presets: @@ -342,6 +376,10 @@ def list_models(): if p.get("bench"): meta["bench"] = p["bench"] + ctx_len = jean_ctx.get(model_id) + if ctx_len: + meta["context_length"] = ctx_len + if meta: model_info["meta"] = meta @@ -372,6 +410,8 @@ def list_models(): meta["quantization"] = details["quantization_level"] if details.get("family"): meta["family"] = details["family"] + if details.get("context_length"): + meta["context_length"] = details["context_length"] if m.get("capabilities"): meta["capabilities"] = m["capabilities"]