The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(nous): list on-sale models in the paid-tier picker
Steve Dalonzod31a2cc684fc
diff --git a/hermes_cli/model_setup_flows.py b/hermes_cli/model_setup_flows.pyindex 025f5ece278..64dbb38181c 100644--- a/hermes_cli/model_setup_flows.py+++ b/hermes_cli/model_setup_flows.py@@ -179,14 +179,15 @@ def _nous_model_catalog(free_tier: bool, portal_url: str, model_ids: list, pricifrom hermes_cli.models_pricing import nous_policy_allowed_ids, restrict_to_nous_policyfrom hermes_cli.models import (partition_nous_models_by_tier,+ union_with_nous_on_sale_models,union_with_portal_free_recommendations,union_with_portal_paid_recommendations,)# Free users: union with the Portal's freeRecommendedModels (newly launched free models appear# before the curated list catches up), then partition selectable/unavailable by Portal pricing.- # Paid users: paidRecommendedModels, no partition. Org policy narrows BEFORE the tier split so a- # rescued id still has to pass the free/paid predicate.+ # Paid users: paidRecommendedModels plus every model on sale right now, no partition. Org policy+ # narrows BEFORE the tier split so a rescued id still has to pass the free/paid predicate.unavailable_models: list[str] = []unavailable_message = ""_policy_allowed = nous_policy_allowed_ids()@@ -200,6 +201,7 @@ def _nous_model_catalog(free_tier: bool, portal_url: str, model_ids: list, pricimodel_ids, pricing = union_with_portal_free_recommendations(model_ids, pricing, portal_url)else:model_ids, pricing = union_with_portal_paid_recommendations(model_ids, pricing, portal_url)+ model_ids = union_with_nous_on_sale_models(model_ids, pricing)_before_policy = model_idsmodel_ids = restrict_to_nous_policy(model_ids, _policy_allowed, rescue_empty=True)_policy_narrowed = model_ids != _before_policydiff --git a/hermes_cli/model_switch_providers.py b/hermes_cli/model_switch_providers.pyindex b0860b6c890..9b9dd570831 100644--- a/hermes_cli/model_switch_providers.py+++ b/hermes_cli/model_switch_providers.py@@ -457,12 +457,13 @@ def _nous_picker_model_ids(curated: dict, force_fresh_nous_tier: bool) -> list:from hermes_cli.models_pricing import get_pricing_for_providerfrom hermes_cli.models import (check_nous_free_tier,+ union_with_nous_on_sale_models,union_with_portal_free_recommendations,union_with_portal_paid_recommendations,)from hermes_cli.auth import get_provider_auth_state- # 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.+ # Cache-only: a cold cache must not hold the picker open. The Portal unions only append ids;+ # the on-sale union reads the same cached rows (the background prewarm fills them).pricing = get_pricing_for_provider("nous", cached_only=True) or {}try:portal = (get_provider_auth_state("nous") or {}).get("portal_base_url", "") or ""@@ -472,6 +473,7 @@ def _nous_picker_model_ids(curated: dict, force_fresh_nous_tier: bool) -> list:model_ids, _ = union_with_portal_free_recommendations(model_ids, pricing, portal)else:model_ids, _ = union_with_portal_paid_recommendations(model_ids, pricing, portal)+ model_ids = union_with_nous_on_sale_models(model_ids, pricing)except Exception:passtry:diff --git a/hermes_cli/models.py b/hermes_cli/models.pyindex 435e5e8b121..99a89fbd872 100644--- a/hermes_cli/models.py+++ b/hermes_cli/models.py@@ -280,6 +280,25 @@ def union_with_portal_paid_recommendations(force_refresh=force_refresh, synthesize_free_pricing=False)+def union_with_nous_on_sale_models(curated_ids: list[str], pricing: dict[str, dict[str, Any]]) -> list[str]:+ """Curated list plus every paid Nous model the gateway is discounting right now, deepest+ discount first. A sale lives only in ``/v1/models`` ``pricing.original``, so without this the+ picker badges discounts on curated rows but never shows a discounted model the curated list and+ Portal recommendations omit. Free rows stay with ``freeRecommendedModels``; rows the gateway+ marks tool-less (``"tools": False``) are skipped because Hermes is tool-calling-first."""+ from hermes_cli.models_pricing import compute_sale_discount++ seen = set(curated_ids)+ on_sale: list[tuple[int, str]] = []+ for mid, entry in (pricing or {}).items():+ if mid in seen or not isinstance(entry, dict) or entry.get("tools") is False:+ continue+ sale = compute_sale_discount(entry.get("prompt", ""), entry.get("completion", ""), entry.get("original"))+ if sale is not None and isinstance(entry.get("original"), dict) and sale[0] < 100:+ on_sale.append((-sale[0], mid))+ return list(curated_ids) + [mid for _, mid in sorted(on_sale)]++# Free-tier detection cache, per profile — short so an account upgrade shows within minutes._FREE_TIER_CACHE_TTL: int = 180 # seconds_free_tier_cache: dict[str, tuple[bool, float]] = {} # profile key -> (result, timestamp)diff --git a/hermes_cli/models_pricing.py b/hermes_cli/models_pricing.pyindex 98c1c5a5f42..01ec36202f0 100644--- a/hermes_cli/models_pricing.py+++ b/hermes_cli/models_pricing.py@@ -224,7 +224,7 @@ def fetch_models_with_pricing(...}}``, cached per *base_url* and per credential so one caller's catalog never answersanother's read. *include_sale_original* (Nous Portal only) copies the gateway's pre-discount``pricing.original`` rates through as a nested ``original`` dict for sale chrome."""- from hermes_cli.models import _HERMES_USER_AGENT+ from hermes_cli.models import _HERMES_USER_AGENT, _openrouter_model_supports_toolsurl_root = (base_url or "").rstrip("/")cache_key = url_root + _pricing_auth_fingerprint(api_key)if not force_refresh:@@ -259,6 +259,9 @@ def fetch_models_with_pricing(# Nous Portal-only: the gateway bills this row to a subscription the account holds, not to credits.if include_sale_original and item.get("billing_mode") == "subscription":entry["billing_mode"] = "subscription"+ # Nous Portal-only: on-sale rows join the picker, which must not offer a tool-less model.+ if include_sale_original and not _openrouter_model_supports_tools(item):+ entry["tools"] = Falseresult[mid] = entryreturn _cache_catalog(cache_key, result, cache_ttl_seconds)diff --git a/tests/hermes_cli/test_nous_picker_on_sale.py b/tests/hermes_cli/test_nous_picker_on_sale.pynew file mode 100644index 00000000000..dd9b8a5cca1--- /dev/null+++ b/tests/hermes_cli/test_nous_picker_on_sale.py@@ -0,0 +1,108 @@+"""Paid-tier Nous pickers surface every model the gateway is discounting, not only curated ones.++A sale exists only in the live ``/v1/models`` ``pricing.original``; the curated manifest and the+Portal's ``paidRecommendedModels`` can both omit a model while it is heavily discounted, and the+picker then badged discounts on curated rows while hiding the deepest ones.+"""++from __future__ import annotations++import json+from unittest.mock import MagicMock++import hermes_cli.models as models_mod+import hermes_cli.models_pricing as mp+from hermes_cli import model_setup_flows+from hermes_cli import model_switch_providers as msp+from hermes_cli.models import union_with_nous_on_sale_models+from hermes_cli.models_pricing import fetch_models_with_pricing++_LIST = {"prompt": "0.000002", "completion": "0.00001"}+++def _sale(pct_off: int) -> dict:+ now = 0.000002 * (100 - pct_off) / 100+ return {"prompt": f"{now:.10f}", "completion": "0.00001", "original": dict(_LIST)}+++def test_appends_discounted_models_missing_from_list_deepest_first():+ pricing = {"curated/a": _sale(40), "sale/small": _sale(20), "sale/deep": _sale(80), "full/price": dict(_LIST)}++ ids = union_with_nous_on_sale_models(["curated/a"], pricing)++ assert ids[0] == "curated/a" # curated order preserved, not duplicated+ assert ids.count("curated/a") == 1+ assert ids[1:] == ["sale/deep", "sale/small"]+ assert "full/price" not in ids+++def test_skips_tool_less_and_free_rows():+ """Free rows belong to freeRecommendedModels; tool-less rows can't drive the agent loop."""+ pricing = {+ "sale/no-tools": {**_sale(70), "tools": False},+ "free/with-original": {"prompt": "0", "completion": "0", "original": dict(_LIST)},+ "free/native": {"prompt": "0", "completion": "0"},+ }+ assert union_with_nous_on_sale_models(["c"], pricing) == ["c"]+++def test_no_pricing_leaves_list_unchanged():+ assert union_with_nous_on_sale_models(["a", "b"], {}) == ["a", "b"]+++def _serve(monkeypatch, payload: dict) -> None:+ resp = MagicMock()+ resp.read.return_value = json.dumps(payload).encode()+ resp.__enter__ = lambda self: self+ resp.__exit__ = lambda *a: False+ monkeypatch.setattr(models_mod, "_urlopen_model_catalog_request", lambda req, timeout=8.0: resp)+++def test_nous_fetch_flags_tool_less_rows_so_the_union_can_skip_them(monkeypatch):+ mp._pricing_cache.clear()+ _serve(monkeypatch, {"data": [+ {"id": "t/yes", "supported_parameters": ["tools"], "pricing": _sale(50)},+ {"id": "t/no", "supported_parameters": ["temperature"], "pricing": _sale(50)},+ {"id": "t/unknown", "pricing": _sale(50)}, # absent field is permissive, as elsewhere+ ]})+ fetch = lambda **kw: fetch_models_with_pricing(api_key="sk-test", base_url="https://example.test",+ force_refresh=True, **kw)+ nous = fetch(include_sale_original=True)+ # Equal discounts tie-break by id, so the order is deterministic.+ assert union_with_nous_on_sale_models([], nous) == ["t/unknown", "t/yes"]+ # Other catalogs never carry the Nous-only flag.+ assert all("tools" not in row for row in fetch().values())+++def _stub_portal(monkeypatch, *, free_tier: bool, pricing: dict, allowed=None) -> None:+ monkeypatch.setattr(mp, "get_pricing_for_provider", lambda provider, **kw: pricing)+ monkeypatch.setattr("hermes_cli.models.check_nous_free_tier", lambda **kw: free_tier)+ monkeypatch.setattr("hermes_cli.models.fetch_nous_recommended_models", lambda *a, **kw: None)+ monkeypatch.setattr(mp, "nous_policy_allowed_ids", lambda **kw: allowed)+++def test_gui_picker_paid_tier_shows_on_sale_model(monkeypatch):+ _stub_portal(monkeypatch, free_tier=False, pricing={"nous/a": dict(_LIST), "sale/x": _sale(80)})+ assert msp._nous_picker_model_ids({"nous": ["nous/a"]}, False) == ["nous/a", "sale/x"]+++def test_gui_picker_free_tier_does_not_list_paid_sales(monkeypatch):+ _stub_portal(monkeypatch, free_tier=True, pricing={"nous/a": dict(_LIST), "sale/x": _sale(80)})+ assert "sale/x" not in msp._nous_picker_model_ids({"nous": ["nous/a"]}, False)+++def test_gui_picker_org_policy_still_narrows_on_sale_models(monkeypatch):+ _stub_portal(monkeypatch, free_tier=False, pricing={"nous/a": dict(_LIST), "sale/x": _sale(80)},+ allowed={"nous/a"})+ assert "sale/x" not in msp._nous_picker_model_ids({"nous": ["nous/a"]}, False)+++def test_cli_setup_flow_and_gui_picker_agree(monkeypatch):+ """``hermes model`` and the GUI/in-chat picker list the same Nous models for a paid account."""+ pricing = {"nous/a": dict(_LIST), "sale/x": _sale(80), "sale/y": _sale(30)}+ _stub_portal(monkeypatch, free_tier=False, pricing=pricing)+ monkeypatch.setattr(mp, "nous_policy_allowed_ids", lambda **kw: None)++ cli = model_setup_flows._nous_model_catalog(False, "", ["nous/a"], pricing)+ assert cli is not None+ assert cli[0] == msp._nous_picker_model_ids({"nous": ["nous/a"]}, False)