diff --git a/jean-router/app.py b/jean-router/app.py index 1b47687..c13703d 100644 --- a/jean-router/app.py +++ b/jean-router/app.py @@ -554,6 +554,7 @@ def list_models(): for p in presets: model_id = p["id"] + model_name = p.get("name", model_id) ctx_len = jean_ctx.get(model_id) caps = jean_caps.get(model_id, ["completion", "tools"]) @@ -561,12 +562,12 @@ def list_models(): caps = list(dict.fromkeys(caps + ["thinking"])) model_info = { - "id": model_id, + "id": model_name, "object": "model", "created": int(time.time()), "owned_by": "jean", "permission": [], - "root": model_id, + "root": model_name, "parent": None, } @@ -659,26 +660,30 @@ def chat_completions(): return jsonify({"error": "model parameter required"}), 400 presets = get_presets() - jean_preset_ids = [p["id"] for p in presets] + jean_preset_ids = {p["id"] for p in presets} + jean_name_to_id = {p.get("name", p["id"]): p["id"] for p in presets} + jean_names = set(jean_name_to_id.keys()) + + if model_id in jean_preset_ids or model_id in jean_names: + internal_id = jean_name_to_id.get(model_id, model_id) - if model_id in jean_preset_ids: if not ensure_vram_for_backend("jean"): return jsonify({"error": "Failed to prepare VRAM for Jean"}), 503 with switch_lock: active = get_active_preset() current_active = active["id"] if active else last_active_preset - if current_active != model_id: - log.info(f"[Router] Switch Jean requis: {current_active or 'none'} → {model_id}") - if not switch_preset(model_id): + if current_active != internal_id: + log.info(f"[Router] Switch Jean requis: {current_active or 'none'} → {internal_id} ({model_id})") + if not switch_preset(internal_id): return jsonify({"error": f"Failed to switch to preset {model_id}"}), 503 else: log.info(f"[Router] Preset {model_id} déjà actif (tracké)") - preset = next((p for p in presets if p["id"] == model_id), {}) + preset = next((p for p in presets if p["id"] == internal_id), {}) if preset.get("reasoning") == "on": ctx, _ = get_jean_metadata() - ctx_len = ctx.get(model_id, 131072) + ctx_len = ctx.get(internal_id, 131072) req_max = data.get("max_tokens", 0) if req_max and req_max > 0: new_max = min(req_max * 2, ctx_len)