jean-router: utiliser le nom d'affichage (name) comme id modele
- /v1/models expose name au lieu de l'id technique des presets Jean - Routing: resolution name -> id interne pour le switch - Correspondance bidirectionnelle dans chat_completions
This commit is contained in:
+14
-9
@@ -554,6 +554,7 @@ def list_models():
|
|||||||
|
|
||||||
for p in presets:
|
for p in presets:
|
||||||
model_id = p["id"]
|
model_id = p["id"]
|
||||||
|
model_name = p.get("name", model_id)
|
||||||
|
|
||||||
ctx_len = jean_ctx.get(model_id)
|
ctx_len = jean_ctx.get(model_id)
|
||||||
caps = jean_caps.get(model_id, ["completion", "tools"])
|
caps = jean_caps.get(model_id, ["completion", "tools"])
|
||||||
@@ -561,12 +562,12 @@ def list_models():
|
|||||||
caps = list(dict.fromkeys(caps + ["thinking"]))
|
caps = list(dict.fromkeys(caps + ["thinking"]))
|
||||||
|
|
||||||
model_info = {
|
model_info = {
|
||||||
"id": model_id,
|
"id": model_name,
|
||||||
"object": "model",
|
"object": "model",
|
||||||
"created": int(time.time()),
|
"created": int(time.time()),
|
||||||
"owned_by": "jean",
|
"owned_by": "jean",
|
||||||
"permission": [],
|
"permission": [],
|
||||||
"root": model_id,
|
"root": model_name,
|
||||||
"parent": None,
|
"parent": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -659,26 +660,30 @@ def chat_completions():
|
|||||||
return jsonify({"error": "model parameter required"}), 400
|
return jsonify({"error": "model parameter required"}), 400
|
||||||
|
|
||||||
presets = get_presets()
|
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"):
|
if not ensure_vram_for_backend("jean"):
|
||||||
return jsonify({"error": "Failed to prepare VRAM for Jean"}), 503
|
return jsonify({"error": "Failed to prepare VRAM for Jean"}), 503
|
||||||
|
|
||||||
with switch_lock:
|
with switch_lock:
|
||||||
active = get_active_preset()
|
active = get_active_preset()
|
||||||
current_active = active["id"] if active else last_active_preset
|
current_active = active["id"] if active else last_active_preset
|
||||||
if current_active != model_id:
|
if current_active != internal_id:
|
||||||
log.info(f"[Router] Switch Jean requis: {current_active or 'none'} → {model_id}")
|
log.info(f"[Router] Switch Jean requis: {current_active or 'none'} → {internal_id} ({model_id})")
|
||||||
if not switch_preset(model_id):
|
if not switch_preset(internal_id):
|
||||||
return jsonify({"error": f"Failed to switch to preset {model_id}"}), 503
|
return jsonify({"error": f"Failed to switch to preset {model_id}"}), 503
|
||||||
else:
|
else:
|
||||||
log.info(f"[Router] Preset {model_id} déjà actif (tracké)")
|
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":
|
if preset.get("reasoning") == "on":
|
||||||
ctx, _ = get_jean_metadata()
|
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)
|
req_max = data.get("max_tokens", 0)
|
||||||
if req_max and req_max > 0:
|
if req_max and req_max > 0:
|
||||||
new_max = min(req_max * 2, ctx_len)
|
new_max = min(req_max * 2, ctx_len)
|
||||||
|
|||||||
Reference in New Issue
Block a user