mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-17 09:34:48 +00:00
fix(proxy): name the entry holding the cap in the team model budget raise refusal
This commit is contained in:
parent
21b0cf1fcb
commit
67f921404b
2 changed files with 27 additions and 5 deletions
|
|
@ -1498,11 +1498,13 @@ def _check_team_model_budget_update_authority(
|
|||
for entry, proposed in requested.items():
|
||||
existing = _existing_model_cap(existing_model_max_budget.get(entry))
|
||||
if existing is not None:
|
||||
_check_existing_model_cap_kept(entry=entry, proposed=proposed, existing=existing)
|
||||
_check_existing_model_cap_kept(entry=entry, cap_entry=entry, proposed=proposed, existing=existing)
|
||||
continue
|
||||
governing = resolve_model_budget(model=entry, model_max_budget=existing_model_max_budget, team_id=data.team_id)
|
||||
if governing is not None and entry_names_model(entry=governing.budget_model, model=entry):
|
||||
_check_existing_model_cap_kept(entry=entry, proposed=proposed, existing=governing.budget_config)
|
||||
_check_existing_model_cap_kept(
|
||||
entry=entry, cap_entry=governing.budget_model, proposed=proposed, existing=governing.budget_config
|
||||
)
|
||||
_check_new_entry_outranks_no_cap(
|
||||
entry=entry,
|
||||
existing_model_max_budget=existing_model_max_budget,
|
||||
|
|
@ -1511,7 +1513,7 @@ def _check_team_model_budget_update_authority(
|
|||
)
|
||||
|
||||
|
||||
def _check_existing_model_cap_kept(entry: str, proposed: BudgetConfig, existing: BudgetConfig) -> None:
|
||||
def _check_existing_model_cap_kept(entry: str, cap_entry: str, proposed: BudgetConfig, existing: BudgetConfig) -> None:
|
||||
if existing.max_budget is None or not _looser_model_cap(proposed=proposed, cap=existing):
|
||||
return
|
||||
raise HTTPException(
|
||||
|
|
@ -1519,8 +1521,8 @@ def _check_existing_model_cap_kept(entry: str, proposed: BudgetConfig, existing:
|
|||
detail={
|
||||
"error": (
|
||||
f"Only a proxy admin can raise a team's model_max_budget for {entry!r} or change its "
|
||||
f"budget_duration. Current max_budget={existing.max_budget} per {existing.budget_duration}, "
|
||||
f"requested={proposed.max_budget} per {proposed.budget_duration}."
|
||||
f"budget_duration. Current max_budget={existing.max_budget} per {existing.budget_duration} "
|
||||
f"(entry {cap_entry!r}), requested={proposed.max_budget} per {proposed.budget_duration}."
|
||||
)
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -17571,6 +17571,26 @@ def test_team_admin_cannot_loosen_team_model_caps(requested) -> None:
|
|||
assert "proxy admin" in exc.value.detail["error"]
|
||||
|
||||
|
||||
def test_team_cap_refusal_names_the_entry_holding_the_cap() -> None:
|
||||
from litellm.proxy.management_endpoints.team_endpoints import _check_team_model_budget_update_authority
|
||||
|
||||
with pytest.raises(HTTPException) as exc:
|
||||
_check_team_model_budget_update_authority(
|
||||
data=UpdateTeamRequest(
|
||||
team_id="t1",
|
||||
model_max_budget={
|
||||
**_EXISTING_TEAM_MODEL_CAPS,
|
||||
"openai/gpt-4o": {"max_budget": 1000.0, "budget_duration": "1d"},
|
||||
},
|
||||
),
|
||||
user_api_key_dict=UserAPIKeyAuth(user_role=LitellmUserRoles.INTERNAL_USER, user_id="team-admin"),
|
||||
existing_model_max_budget=_EXISTING_TEAM_MODEL_CAPS,
|
||||
)
|
||||
assert exc.value.status_code == 403
|
||||
assert "for 'openai/gpt-4o'" in exc.value.detail["error"]
|
||||
assert "(entry 'gpt-4o')" in exc.value.detail["error"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"requested",
|
||||
[
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue