From d6164cdadb5a8139077b32f4e93b7018fc108ef1 Mon Sep 17 00:00:00 2001 From: happy5318 Date: Sat, 2 May 2026 13:40:38 +0800 Subject: [PATCH] Fix _norm_model_id to properly strip provider prefixes The _norm_model_id function was using split(':', 1)[1] which only removed the first colon-separated segment, leaving provider names in the normalized model ID. For example, '@custom:jingdong:GLM-5' became 'jingdong:glm.5' instead of 'glm.5'. This caused the default model injection check to fail, resulting in a duplicate 'Default' group being added to the model list even when the model already existed with a provider prefix. Changes: - Use split(':')[-1] to get the last segment after all colons - Use split('/')[-1] consistently for slash-separated paths - Replace local _norm lambda with _norm_model_id function call Fixes duplicate Default group appearing in model dropdown when using custom providers with @provider:model ID format. --- api/config.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/api/config.py b/api/config.py index 9cc61299..fd40fc40 100644 --- a/api/config.py +++ b/api/config.py @@ -1506,10 +1506,13 @@ def get_available_models() -> dict: def _norm_model_id(model_id: str) -> str: s = str(model_id or "").strip().lower() + # Strip @provider: prefix (e.g., @custom:jingdong:GLM-5 -> GLM-5) if s.startswith("@") and ":" in s: - s = s.split(":", 1)[1] + # Split on all colons and take the last part + s = s.split(":")[-1] + # Strip provider/model prefix (e.g., custom:jingdong/GLM-5 -> GLM-5) if "/" in s: - s = s.split("/", 1)[1] + s = s.split("/")[-1] return s.replace("-", ".") def _build_configured_model_badges() -> dict[str, dict[str, str]]: @@ -2079,9 +2082,8 @@ def get_available_models() -> dict: ) if default_model: - _norm = lambda mid: (mid.split("/", 1)[-1] if "/" in mid else mid).replace("-", ".") - all_ids_norm = {_norm(m["id"]) for g in groups for m in g.get("models", [])} - if _norm(default_model) not in all_ids_norm: + all_ids_norm = {_norm_model_id(m["id"]) for g in groups for m in g.get("models", [])} + if _norm_model_id(default_model) not in all_ids_norm: label = _get_label_for_model(default_model, groups) target_display = ( _PROVIDER_DISPLAY.get(active_provider, active_provider or "").lower()