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.
This commit is contained in:
happy5318
2026-05-02 13:40:38 +08:00
parent 4e0dce9a03
commit d6164cdadb
+7 -5
View File
@@ -1506,10 +1506,13 @@ def get_available_models() -> dict:
def _norm_model_id(model_id: str) -> str: def _norm_model_id(model_id: str) -> str:
s = str(model_id or "").strip().lower() s = str(model_id or "").strip().lower()
# Strip @provider: prefix (e.g., @custom:jingdong:GLM-5 -> GLM-5)
if s.startswith("@") and ":" in s: 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: if "/" in s:
s = s.split("/", 1)[1] s = s.split("/")[-1]
return s.replace("-", ".") return s.replace("-", ".")
def _build_configured_model_badges() -> dict[str, dict[str, str]]: def _build_configured_model_badges() -> dict[str, dict[str, str]]:
@@ -2079,9 +2082,8 @@ def get_available_models() -> dict:
) )
if default_model: if default_model:
_norm = lambda mid: (mid.split("/", 1)[-1] if "/" in mid else mid).replace("-", ".") all_ids_norm = {_norm_model_id(m["id"]) for g in groups for m in g.get("models", [])}
all_ids_norm = {_norm(m["id"]) for g in groups for m in g.get("models", [])} if _norm_model_id(default_model) not in all_ids_norm:
if _norm(default_model) not in all_ids_norm:
label = _get_label_for_model(default_model, groups) label = _get_label_for_model(default_model, groups)
target_display = ( target_display = (
_PROVIDER_DISPLAY.get(active_provider, active_provider or "").lower() _PROVIDER_DISPLAY.get(active_provider, active_provider or "").lower()