fix(inventory): avoid fresh Nous tier checks in picker payloads

This commit is contained in:
helix4u
2026-06-07 00:41:13 -07:00
committed by kshitij
parent 846821d8c0
commit eb70ab894b
3 changed files with 106 additions and 4 deletions
+15 -3
View File
@@ -116,6 +116,7 @@ def build_models_payload(
canonical_order: bool = False,
pricing: bool = False,
capabilities: bool = False,
force_fresh_nous_tier: bool = False,
max_models: int = 50,
) -> dict:
"""Build the ``{providers, model, provider}`` shape every consumer
@@ -139,6 +140,10 @@ def build_models_payload(
``{model: {fast, reasoning}}`` so pickers can gate the model-options
controls (fast toggle / reasoning) to what each model actually
supports, instead of offering knobs the backend would reject.
- ``force_fresh_nous_tier``: bypass the short Nous free-tier cache when
selecting Portal-recommended Nous models and applying tier gating. Keep
this false for UI picker opens; explicit auth/model flows can opt in
when they need freshly-purchased credits to show up immediately.
"""
from hermes_cli.model_switch import list_authenticated_providers
@@ -148,6 +153,7 @@ def build_models_payload(
current_model=ctx.current_model,
user_providers=ctx.user_providers,
custom_providers=ctx.custom_providers,
force_fresh_nous_tier=force_fresh_nous_tier,
max_models=max_models,
)
@@ -158,7 +164,7 @@ def build_models_payload(
if canonical_order:
rows = _reorder_canonical(rows)
if pricing:
_apply_pricing(rows)
_apply_pricing(rows, force_fresh_nous_tier=force_fresh_nous_tier)
if capabilities:
_apply_capabilities(rows)
@@ -293,7 +299,11 @@ def _reorder_canonical(rows: list[dict]) -> list[dict]:
return canon + extras
def _apply_pricing(rows: list[dict]) -> None:
def _apply_pricing(
rows: list[dict],
*,
force_fresh_nous_tier: bool = False,
) -> None:
"""Enrich each provider row with per-model pricing + Nous tier gating.
Mutates ``rows`` in-place. For every row whose provider supports live
@@ -359,7 +369,9 @@ def _apply_pricing(rows: list[dict]) -> None:
if slug == "nous":
try:
if nous_free_tier is None:
nous_free_tier = check_nous_free_tier(force_fresh=True)
nous_free_tier = check_nous_free_tier(
force_fresh=force_fresh_nous_tier
)
row["free_tier"] = bool(nous_free_tier)
if nous_free_tier:
_selectable, unavailable = partition_nous_models_by_tier(
+5 -1
View File
@@ -1178,6 +1178,7 @@ def list_authenticated_providers(
current_base_url: str = "",
user_providers: dict = None,
custom_providers: list | None = None,
force_fresh_nous_tier: bool = False,
max_models: int = 8,
current_model: str = "",
) -> List[dict]:
@@ -1197,6 +1198,9 @@ def list_authenticated_providers(
- source: str — "built-in", "models.dev", "user-config"
Only includes providers that have API keys set or are user-defined endpoints.
``force_fresh_nous_tier`` bypasses the short Nous tier cache for explicit
account-sensitive flows. UI picker opens should leave it false so they do
not block on fresh Portal/account checks every time.
"""
import os
from agent.models_dev import (
@@ -1539,7 +1543,7 @@ def list_authenticated_providers(
_portal = _st.get("portal_base_url", "") or ""
except Exception:
_portal = ""
if _nous_free(force_fresh=True):
if _nous_free(force_fresh=force_fresh_nous_tier):
model_ids, _ = _union_free(model_ids, _pricing, _portal)
else:
model_ids, _ = _union_paid(model_ids, _pricing, _portal)