fix(nous): apply the org policy before the free/paid tier split
Rescuing an empty list after partitioning put paid models back into a free-tier user's selectable list, and the dashboard could pick one as the silent default. Narrowing first also drops the separate unavailable-list filter.
This commit is contained in:
+9
-9
@@ -9392,6 +9392,9 @@ def _login_nous(args, pconfig: ProviderConfig) -> None:
|
||||
# purchases are reflected immediately.
|
||||
free_tier = check_nous_free_tier(force_fresh=True)
|
||||
_portal_for_recs = auth_state.get("portal_base_url", "")
|
||||
# Narrow before the tier split, so a rescued id still has to
|
||||
# pass the free/paid predicate.
|
||||
_policy_allowed = nous_policy_allowed_ids()
|
||||
if free_tier:
|
||||
try:
|
||||
from hermes_cli.nous_account import (
|
||||
@@ -9417,6 +9420,9 @@ def _login_nous(args, pconfig: ProviderConfig) -> None:
|
||||
model_ids, pricing = union_with_portal_free_recommendations(
|
||||
model_ids, pricing, _portal_for_recs,
|
||||
)
|
||||
model_ids = restrict_to_nous_policy(
|
||||
model_ids, _policy_allowed, rescue_empty=True,
|
||||
)
|
||||
model_ids, unavailable_models = partition_nous_models_by_tier(
|
||||
model_ids, pricing, free_tier=True,
|
||||
)
|
||||
@@ -9428,15 +9434,9 @@ def _login_nous(args, pconfig: ProviderConfig) -> None:
|
||||
model_ids, pricing = union_with_portal_paid_recommendations(
|
||||
model_ids, pricing, _portal_for_recs,
|
||||
)
|
||||
# Neither the curated list nor the Portal's recommendations
|
||||
# know what the org may reach.
|
||||
_policy_allowed = nous_policy_allowed_ids()
|
||||
model_ids = restrict_to_nous_policy(
|
||||
model_ids, _policy_allowed, rescue_empty=True,
|
||||
)
|
||||
unavailable_models = restrict_to_nous_policy(
|
||||
unavailable_models, _policy_allowed,
|
||||
)
|
||||
model_ids = restrict_to_nous_policy(
|
||||
model_ids, _policy_allowed, rescue_empty=True,
|
||||
)
|
||||
_portal = auth_state.get("portal_base_url", "")
|
||||
if model_ids:
|
||||
from hermes_cli.nous_account import nous_policy_notice
|
||||
|
||||
@@ -531,6 +531,14 @@ def _model_flow_nous(config, current_model="", args=None):
|
||||
# of CLI release cadence.
|
||||
unavailable_models: list[str] = []
|
||||
unavailable_message = ""
|
||||
|
||||
# Neither the curated list nor the Portal's recommendations know what the
|
||||
# org may reach. Narrow before the tier split, so an id the policy rescues
|
||||
# still has to pass the free/paid predicate instead of going around it.
|
||||
from hermes_cli.models import nous_policy_allowed_ids, restrict_to_nous_policy
|
||||
|
||||
_policy_allowed = nous_policy_allowed_ids()
|
||||
|
||||
if free_tier:
|
||||
try:
|
||||
from hermes_cli.nous_account import (
|
||||
@@ -551,6 +559,9 @@ def _model_flow_nous(config, current_model="", args=None):
|
||||
model_ids, pricing = union_with_portal_free_recommendations(
|
||||
model_ids, pricing, _nous_portal_url,
|
||||
)
|
||||
model_ids = restrict_to_nous_policy(
|
||||
model_ids, _policy_allowed, rescue_empty=True,
|
||||
)
|
||||
model_ids, unavailable_models = partition_nous_models_by_tier(
|
||||
model_ids, pricing, free_tier=True
|
||||
)
|
||||
@@ -558,16 +569,9 @@ def _model_flow_nous(config, current_model="", args=None):
|
||||
model_ids, pricing = union_with_portal_paid_recommendations(
|
||||
model_ids, pricing, _nous_portal_url,
|
||||
)
|
||||
|
||||
# Neither the curated list nor the Portal's recommendations know what the
|
||||
# org may reach.
|
||||
from hermes_cli.models import nous_policy_allowed_ids, restrict_to_nous_policy
|
||||
|
||||
_policy_allowed = nous_policy_allowed_ids()
|
||||
model_ids = restrict_to_nous_policy(
|
||||
model_ids, _policy_allowed, rescue_empty=True,
|
||||
)
|
||||
unavailable_models = restrict_to_nous_policy(unavailable_models, _policy_allowed)
|
||||
model_ids = restrict_to_nous_policy(
|
||||
model_ids, _policy_allowed, rescue_empty=True,
|
||||
)
|
||||
|
||||
if not model_ids and not unavailable_models:
|
||||
print("No models available for Nous Portal after filtering.")
|
||||
|
||||
@@ -7505,10 +7505,19 @@ def get_recommended_default_model(provider: str = ""):
|
||||
except Exception:
|
||||
portal_url = ""
|
||||
|
||||
# This endpoint picks the model a user lands on without choosing it,
|
||||
# so an unreachable one here is worse than in a picker. Narrow before
|
||||
# the tier split, so a rescued id still has to pass the free/paid
|
||||
# predicate.
|
||||
_policy_allowed = nous_policy_allowed_ids()
|
||||
|
||||
if free_tier:
|
||||
model_ids, pricing = union_with_portal_free_recommendations(
|
||||
model_ids, pricing, portal_url
|
||||
)
|
||||
model_ids = restrict_to_nous_policy(
|
||||
model_ids, _policy_allowed, rescue_empty=True,
|
||||
)
|
||||
model_ids, _unavailable = partition_nous_models_by_tier(
|
||||
model_ids, pricing, free_tier=True
|
||||
)
|
||||
@@ -7516,12 +7525,9 @@ def get_recommended_default_model(provider: str = ""):
|
||||
model_ids, pricing = union_with_portal_paid_recommendations(
|
||||
model_ids, pricing, portal_url
|
||||
)
|
||||
|
||||
# This endpoint picks the model a user lands on without choosing
|
||||
# it, so an unreachable one here is worse than in a picker.
|
||||
model_ids = restrict_to_nous_policy(
|
||||
model_ids, nous_policy_allowed_ids(), rescue_empty=True,
|
||||
)
|
||||
model_ids = restrict_to_nous_policy(
|
||||
model_ids, _policy_allowed, rescue_empty=True,
|
||||
)
|
||||
|
||||
model = pick_silent_default_model(model_ids, provider="nous")
|
||||
return {"provider": "nous", "model": model, "free_tier": bool(free_tier)}
|
||||
|
||||
@@ -213,3 +213,28 @@ class TestRescueIsOptIn:
|
||||
empty — not a filter result to rescue."""
|
||||
reachable = {f"cn/model-{i}" for i in range(42)}
|
||||
assert restrict_to_nous_policy([], reachable) == []
|
||||
|
||||
|
||||
class TestPolicyRunsBeforeTierSplit:
|
||||
"""A rescued id must still pass the free/paid predicate.
|
||||
|
||||
Rescuing after the tier split put paid models back into a free-tier user's
|
||||
selectable list, and the same id into both lists at once.
|
||||
"""
|
||||
|
||||
def test_a_rescued_paid_model_stays_unavailable_for_a_free_tier_user(self):
|
||||
from hermes_cli.models import partition_nous_models_by_tier
|
||||
|
||||
pricing = {
|
||||
"vendor/free": {"prompt": "0", "completion": "0"},
|
||||
"vendor/paid": {"prompt": "0.000002", "completion": "0.00001"},
|
||||
}
|
||||
narrowed = restrict_to_nous_policy(
|
||||
list(pricing), {"vendor/paid"}, rescue_empty=True
|
||||
)
|
||||
selectable, unavailable = partition_nous_models_by_tier(
|
||||
narrowed, pricing, free_tier=True
|
||||
)
|
||||
|
||||
assert selectable == []
|
||||
assert unavailable == ["vendor/paid"]
|
||||
|
||||
Reference in New Issue
Block a user