fix(config): preserve list-format models in custom_providers normalize

_normalize_custom_provider_entry silently drops the models field when it's
a list. Hand-edited configs (and the shape used by older Hermes versions)
still write models as a plain list of ids, so after the normalize pass the
entry reaches list_authenticated_providers() with no models and /model
shows the provider with (0) models — even though the underlying picker
code handles lists fine.

Convert list-format models into the empty-value dict shape the rest of
the pipeline already expects. Dict-format entries keep passing through
unchanged.

Repro (before the fix):

    custom_providers:
    - name: acme
      base_url: https://api.example.com/v1
      models: [foo, bar, baz]

/model shows "acme (0)"; bypassing normalize in list_authenticated_providers
returns three models, confirming the drop happens in normalize.

Adds four unit tests covering list→dict conversion, dict pass-through,
filtering of empty/non-string entries, and the empty-list case.
This commit is contained in:
drstrangerujn 2026-04-21 14:32:17 +02:00 committed by Teknium
parent c80cc8557e
commit a5b0c7e2ec
2 changed files with 53 additions and 0 deletions

View file

@ -2055,6 +2055,14 @@ def _normalize_custom_provider_entry(
models = entry.get("models")
if isinstance(models, dict) and models:
normalized["models"] = models
elif isinstance(models, list) and models:
# Hand-edited configs (and older Hermes versions) write ``models`` as
# a plain list of model ids. Preserve them by converting to the dict
# shape downstream code expects; otherwise normalize silently drops
# the list and /model shows the provider with (0) models.
normalized["models"] = {
str(m): {} for m in models if isinstance(m, str) and m.strip()
}
context_length = entry.get("context_length")
if isinstance(context_length, int) and context_length > 0:

View file

@ -135,3 +135,48 @@ class TestNormalizeCustomProviderEntry:
}
result = _normalize_custom_provider_entry(entry, provider_key="")
assert result is None
def test_models_list_converted_to_dict(self):
"""List-format models should be preserved as an empty-value dict so
/model picks them up instead of showing the provider with (0) models."""
entry = {
"name": "tencent-coding-plan",
"base_url": "https://api.lkeap.cloud.tencent.com/coding/v3",
"models": ["glm-5", "kimi-k2.5", "minimax-m2.5"],
}
result = _normalize_custom_provider_entry(entry)
assert result is not None
assert result["models"] == {"glm-5": {}, "kimi-k2.5": {}, "minimax-m2.5": {}}
def test_models_dict_preserved(self):
"""Dict-format models should pass through unchanged."""
entry = {
"name": "acme",
"base_url": "https://api.example.com/v1",
"models": {"gpt-foo": {"context_length": 32000}},
}
result = _normalize_custom_provider_entry(entry)
assert result is not None
assert result["models"] == {"gpt-foo": {"context_length": 32000}}
def test_models_list_filters_empty_and_non_string(self):
"""List entries that are empty strings or non-strings are skipped."""
entry = {
"name": "acme",
"base_url": "https://api.example.com/v1",
"models": ["valid", "", None, 42, " ", "also-valid"],
}
result = _normalize_custom_provider_entry(entry)
assert result is not None
assert result["models"] == {"valid": {}, "also-valid": {}}
def test_models_empty_list_omitted(self):
"""Empty list (falsy) should not produce a models key."""
entry = {
"name": "acme",
"base_url": "https://api.example.com/v1",
"models": [],
}
result = _normalize_custom_provider_entry(entry)
assert result is not None
assert "models" not in result