fix(model): merge configured models into picker rows (#63055)

Preserve the root cause and precedence direction from #43538 while applying the merge before truncation and covering all declared model shapes.

Co-authored-by: liuhao1024 <sunsky.lau@gmail.com>
This commit is contained in:
Teknium 2026-07-12 03:05:12 -07:00 committed by GitHub
parent 8c77206859
commit 2b5d4ae916
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 53 additions and 0 deletions

View file

@ -1742,6 +1742,15 @@ def list_authenticated_providers(
model_ids = curated.get(hermes_id, [])
if hermes_id in _MODELS_DEV_PREFERRED:
model_ids = _merge_with_models_dev(hermes_id, model_ids)
# A providers.<built-in>.models block extends the provider's discovered
# catalog. Section 3 cannot emit it later because this built-in row owns
# the slug, so merge declarations here before applying max_models.
configured_models: list[str] = []
if isinstance(user_providers, dict):
configured = user_providers.get(hermes_id)
if isinstance(configured, dict):
configured_models = _declared_model_ids(configured.get("models"))
model_ids = list(dict.fromkeys([*configured_models, *model_ids]))
total = len(model_ids)
if hermes_id in _UNCAPPED_PICKER_PROVIDERS:
top = model_ids # Aggregator: show full catalog regardless of max_models

View file

@ -0,0 +1,44 @@
"""Configured models extend built-in picker rows."""
from unittest.mock import patch
from hermes_cli.model_switch import list_authenticated_providers
def _provider_row(configured_models, *, max_models=None):
with (
patch(
"agent.models_dev.fetch_models_dev",
return_value={"deepseek": {"env": ["DEEPSEEK_API_KEY"], "name": "DeepSeek"}},
),
patch(
"agent.models_dev.PROVIDER_TO_MODELS_DEV",
{"deepseek": "deepseek"},
),
patch(
"hermes_cli.models.cached_provider_model_ids",
return_value=["live-a", "shared"],
),
patch("hermes_cli.providers.HERMES_OVERLAYS", {}),
patch.dict("os.environ", {"DEEPSEEK_API_KEY": "test-key"}),
):
rows = list_authenticated_providers(
current_provider="deepseek",
user_providers={"deepseek": {"models": configured_models}},
max_models=max_models,
)
return next(row for row in rows if row["slug"] == "deepseek")
def test_configured_models_precede_and_deduplicate_discovered_models():
row = _provider_row({"configured-x": {}, "shared": {}})
assert row["models"] == ["configured-x", "shared", "live-a"]
assert row["total_models"] == 3
def test_configured_models_are_merged_before_picker_limit():
row = _provider_row(["configured-x", "configured-y"], max_models=2)
assert row["models"] == ["configured-x", "configured-y"]
assert row["total_models"] == 4