perf(picker): read Nous pricing cache-only when building the picker row
_nous_picker_model_ids only uses the ids the Portal unions append — both
unions discard the pricing map (`model_ids, _ = union_with_portal_*`) — yet
it called get_pricing_for_provider("nous") without cached_only, so a cold
pricing cache paid a full /v1/models round-trip (network timeout on a slow
Portal) on the picker-open path for nothing. Pass cached_only=True; the
background pricing prewarm (#101685) fills the same cache for later opens.
Re-derived from #102099 by @finn763: the original patched
hermes_cli/model_switch.py, which 3b1ecfc0a1 decomposed; the live call site is
hermes_cli/model_switch_providers.py.
Based on #102099 by @finn763.
This commit is contained in:
@@ -416,7 +416,9 @@ def _nous_picker_model_ids(curated: dict, force_fresh_nous_tier: bool) -> list:
|
||||
union_with_portal_paid_recommendations,
|
||||
)
|
||||
from hermes_cli.auth import get_provider_auth_state
|
||||
pricing = get_pricing_for_provider("nous") or {}
|
||||
# Cache-only: both Portal unions below discard the pricing map (``model_ids, _ = ...``);
|
||||
# only the appended ids matter, so a live catalog fetch here buys nothing but latency.
|
||||
pricing = get_pricing_for_provider("nous", cached_only=True) or {}
|
||||
try:
|
||||
portal = (get_provider_auth_state("nous") or {}).get("portal_base_url", "") or ""
|
||||
except Exception:
|
||||
|
||||
22
tests/hermes_cli/test_nous_picker_pricing_cached_only.py
Normal file
22
tests/hermes_cli/test_nous_picker_pricing_cached_only.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""The Nous picker row never starts a pricing fetch: the picker only uses the ids the Portal
|
||||
unions append, and a cold pricing cache must not hold the picker open (salvage of #102099)."""
|
||||
|
||||
import hermes_cli.models_pricing as mp
|
||||
from hermes_cli import model_switch_providers as msp
|
||||
|
||||
|
||||
def test_nous_picker_model_ids_reads_pricing_cache_only(monkeypatch):
|
||||
seen: list[bool] = []
|
||||
|
||||
def fake_pricing(provider, *, force_refresh=False, cached_only=False):
|
||||
seen.append(cached_only)
|
||||
return {}
|
||||
|
||||
monkeypatch.setattr(mp, "get_pricing_for_provider", fake_pricing)
|
||||
# Keep the sibling Portal calls off the network; only the pricing call shape is under test.
|
||||
monkeypatch.setattr("hermes_cli.models.check_nous_free_tier", lambda **kw: False)
|
||||
monkeypatch.setattr("hermes_cli.models.fetch_nous_recommended_models", lambda *a, **kw: None)
|
||||
monkeypatch.setattr(mp, "nous_policy_allowed_ids", lambda **kw: None)
|
||||
|
||||
assert msp._nous_picker_model_ids({"nous": ["nous/a"]}, False) == ["nous/a"]
|
||||
assert seen == [True]
|
||||
Reference in New Issue
Block a user