The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(nous): retain positive-price models with rounded full discounts
Steve Dalonzod22e5156444c
diff --git a/hermes_cli/model_switch_providers.py b/hermes_cli/model_switch_providers.pyindex 9b9dd570831..aef8b327d46 100644--- a/hermes_cli/model_switch_providers.py+++ b/hermes_cli/model_switch_providers.py@@ -449,8 +449,8 @@ def _aws_live_or_curated_ids(slug: str, curated: dict, *fallback_keys: str,def _nous_picker_model_ids(curated: dict, force_fresh_nous_tier: bool) -> list:"""Nous serves a huge live catalog; the picker shows ONLY the curated agentic list, augmented- with the Portal's free/paid recommendations (new models surface without a CLI release) and- narrowed by org policy. Mirrors ``_model_flow_nous`` so GUI pickers match the CLI. A failed+ with the Portal's free/paid recommendations and paid-tier sale models, then narrowed by org+ policy. Mirrors ``_model_flow_nous`` so GUI pickers match the CLI. A failedrecommendation fetch still yields a policy-filtered curated list."""model_ids = curated.get("nous", [])try:diff --git a/hermes_cli/models.py b/hermes_cli/models.pyindex c0af28e942e..8024f3b5634 100644--- a/hermes_cli/models.py+++ b/hermes_cli/models.py@@ -287,7 +287,9 @@ def union_with_nous_on_sale_models(curated_ids: list[str], pricing: dict[str, diPortal recommendations omit. Free rows stay with ``freeRecommendedModels``; rows the gatewaymarks tool-less (``"tools": False``) are skipped because Hermes is tool-calling-first, andimage/video generation rows are skipped because they are not chat models."""- from hermes_cli.models_pricing import compute_sale_discount+ from math import isfinite++ from hermes_cli.models_pricing import _price_float, compute_sale_discountseen = set(curated_ids)on_sale: list[tuple[int, str]] = []@@ -295,7 +297,12 @@ def union_with_nous_on_sale_models(curated_ids: list[str], pricing: dict[str, diif mid in seen or not isinstance(entry, dict) or entry.get("tools") is False or entry.get("generation"):continuesale = 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:+ # Badge percentages are rounded: a nearly-free paid row can display 100% off.+ paid = any(+ (rate := _price_float(entry.get(key), positive=True)) is not None and isfinite(rate)+ for key in ("prompt", "completion")+ )+ if sale is not None and isinstance(entry.get("original"), dict) and paid:on_sale.append((-sale[0], mid))return list(curated_ids) + [mid for _, mid in sorted(on_sale)]diff --git a/tests/hermes_cli/test_nous_picker_on_sale.py b/tests/hermes_cli/test_nous_picker_on_sale.pyindex 53579732b65..4ca9f720114 100644--- a/tests/hermes_cli/test_nous_picker_on_sale.py+++ b/tests/hermes_cli/test_nous_picker_on_sale.py@@ -166,3 +166,27 @@ def test_skips_generation_models_on_sale(monkeypatch):nous = fetch_models_with_pricing(api_key="sk-test", base_url="https://example.test",force_refresh=True, include_sale_original=True)assert union_with_nous_on_sale_models([], nous) == ["chat/ok"]+++def test_nonzero_sale_rounding_to_full_discount_is_still_paid():+ """A rounded -100% badge does not make a positive-price model free."""+ pricing = {+ "sale/almost-free": {"prompt": "0.000000001", "completion": "0.000000001", "original": dict(_LIST)},+ "free/zero": {"prompt": "0", "completion": "0", "original": dict(_LIST)},+ }+ assert union_with_nous_on_sale_models([], pricing) == ["sale/almost-free"]+++def test_zero_prompt_with_missing_or_invalid_completion_is_not_a_paid_sale(monkeypatch):+ """The real parser normalizes absent completion to an empty string."""+ mp._pricing_cache.clear()+ rows = [+ {"id": "free/missing", "pricing": {"prompt": "0", "original": dict(_LIST)}},+ *[{"id": f"free/invalid-{i}",+ "pricing": {"prompt": "0", "completion": value, "original": dict(_LIST)}}+ for i, value in enumerate(("", None, "not-a-price", "NaN", "Infinity", "-1", "0"))],+ ]+ _serve(monkeypatch, {"data": rows})+ pricing = fetch_models_with_pricing(api_key="synthetic", base_url="https://example.test",+ force_refresh=True, include_sale_original=True)+ assert union_with_nous_on_sale_models([], pricing) == []