The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(model-picker): stop the 50-model cap cutting the Nous and OpenRouter free tier
teknium1299567629399
diff --git a/gateway/slash_commands_model.py b/gateway/slash_commands_model.pyindex 1f32d7ff080..0d94112b727 100644--- a/gateway/slash_commands_model.py+++ b/gateway/slash_commands_model.py@@ -116,6 +116,9 @@ class _ModelSwitchContext:+_TEXT_LISTING_MODELS = 5++def _model_provider_listing_lines(providers) -> list[str]:"""Text-list body for ``/model`` with no args on platforms without a picker."""lines: list[str] = []@@ -123,8 +126,9 @@ def _model_provider_listing_lines(providers) -> list[str]:tag = t("gateway.model.current_tag") if p["is_current"] else ""lines.append(f"**{p['name']}** `--provider {p['slug']}`{tag}:")if p["models"]:- model_strs = ", ".join(f"`{m}`" for m in p["models"])- hidden = p["total_models"] - len(p["models"])+ shown = p["models"][:_TEXT_LISTING_MODELS] # uncapped rows arrive full; this is a preview+ model_strs = ", ".join(f"`{m}`" for m in shown)+ hidden = p["total_models"] - len(shown)extra = t("gateway.model.more_models_suffix", count=hidden) if hidden > 0 else ""lines.append(f" {model_strs}{extra}")elif p.get("api_url"):@@ -475,7 +479,7 @@ class GatewayModelCommandsMixin:lines = [t("gateway.model.current_label", model=ctx.current_model or t("gateway.shared.unknown_value"),provider=get_label(ctx.current_provider)), ""]try: # off-loop: listing still reads config/disk cache synchronously (#41289)- providers = await asyncio.to_thread(list_authenticated_providers, max_models=5, **listing_kwargs)+ providers = await asyncio.to_thread(list_authenticated_providers, max_models=_TEXT_LISTING_MODELS, **listing_kwargs)lines.extend(_model_provider_listing_lines(providers))except Exception:passdiff --git a/hermes_cli/model_switch_providers.py b/hermes_cli/model_switch_providers.pyindex 292e9c9bace..fc219b42e44 100644--- a/hermes_cli/model_switch_providers.py+++ b/hermes_cli/model_switch_providers.py@@ -20,8 +20,10 @@ from utils import base_url_host_matches# Log-record parity with the origin module.logger = logging.getLogger("hermes_cli.model_switch")-# Aggregators whose full catalogs (70+ models) must stay visible: never capped by max_models.-_UNCAPPED_PICKER_PROVIDERS: frozenset[str] = frozenset({"opencode-zen", "opencode-go"})+# Rows never capped by max_models: aggregators whose full catalogs (70+ models) must stay visible, and+# rows that are already a curated list (Nous = curated + Portal picks, OpenRouter = curated ∩ live),+# where the cap only cut the bottom "Free tier" block and the Portal's appended recommendations.+_UNCAPPED_PICKER_PROVIDERS: frozenset[str] = frozenset({"opencode-zen", "opencode-go", "nous", "openrouter"})def _save_discovered_models_to_config(@@ -504,8 +506,9 @@ def _free_tier_nous_row(row: dict) -> dict | None:def _cap_models(model_ids: list, max_models: int | None, slug: str = "") -> list:- """Apply ``max_models``; aggregators in ``_UNCAPPED_PICKER_PROVIDERS`` show everything."""- if slug in _UNCAPPED_PICKER_PROVIDERS or max_models is None:+ """Apply ``max_models``; rows in ``_UNCAPPED_PICKER_PROVIDERS`` show everything (``0`` still+ means slug-only: no models)."""+ if max_models is None or (max_models and slug in _UNCAPPED_PICKER_PROVIDERS):return model_idsreturn model_ids[:max_models]@@ -1349,7 +1352,7 @@ def list_picker_providers(except Exception:live_ids = list(p.get("models", []))p = dict(p)- p["models"] = live_ids[:max_models] if max_models is not None else live_ids+ p["models"] = _cap_models(live_ids, max_models, "openrouter")p["total_models"] = len(live_ids)is_custom_endpoint = bool(p.get("is_user_defined")) and bool(p.get("api_url"))diff --git a/tests/hermes_cli/test_list_picker_providers.py b/tests/hermes_cli/test_list_picker_providers.pyindex 0e08bbeb76e..05c90152b0e 100644--- a/tests/hermes_cli/test_list_picker_providers.py+++ b/tests/hermes_cli/test_list_picker_providers.py@@ -272,3 +272,20 @@ def test_non_blocking_listing_opens_no_socket(monkeypatch, tmp_path):assert live == [], f"cache-only listing ran live probes in the request path: {live}"assert any(r.get("slug") == "openrouter" and r.get("models") for r in rows), "OpenRouter row lost its curated snapshot"+++def test_curated_openrouter_row_keeps_free_tail_past_max_models(monkeypatch):+ """The OpenRouter row is already curated; its bottom "Free tier" block must survive the picker cap+ while an ordinary provider row stays capped."""+ curated = [(f"vendor/model-{i}", "") for i in range(55)] + [("stealth/free-model", "free, stealth model")]+ other = [f"other-{i}" for i in range(60)]+ monkeypatch.setattr(model_switch, "list_authenticated_providers", lambda **_: [+ _make_provider("openrouter", models=[mid for mid, _ in curated][:50]),+ _make_provider("deepseek", models=other[:50]) | {"total_models": len(other)},+ ])+ monkeypatch.setattr(models_mod, "fetch_openrouter_models", lambda **_: curated)++ rows = {r["slug"]: r for r in model_switch_providers.list_picker_providers(max_models=50)}++ assert rows["openrouter"]["models"] == [mid for mid, _ in curated]+ assert len(rows["deepseek"]["models"]) == 50diff --git a/tests/hermes_cli/test_model_catalog.py b/tests/hermes_cli/test_model_catalog.pyindex 086a2b4a353..17ac9fc8726 100644--- a/tests/hermes_cli/test_model_catalog.py+++ b/tests/hermes_cli/test_model_catalog.py@@ -446,8 +446,9 @@ class TestIntegrationWithModelsModule:full_row = _nous(full)assert full_row is not None and full_row["models"] == expected+ # The Nous row is already curated, so an int cap never trims it (its free tier sits last).one_row = _nous(one)- assert one_row is not None and one_row["models"] == expected[:1]+ assert one_row is not None and one_row["models"] == expectedzero_row = _nous(zero)# 0 means an empty model list — NOT unlimited. total_models still real.