mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
fix(budget): honor zero-valued deployment budgets
Signed-off-by: apex-mochen <2756823972@qq.com>
This commit is contained in:
parent
25c5b73134
commit
38ae83a537
2 changed files with 43 additions and 1 deletions
|
|
@ -841,7 +841,7 @@ class RouterBudgetLimiting(CustomLogger):
|
|||
|
||||
for _model in model_list:
|
||||
_litellm_params = _model.get("litellm_params", {})
|
||||
if _litellm_params.get("max_budget") or _litellm_params.get("budget_duration") is not None:
|
||||
if _litellm_params.get("max_budget") is not None or _litellm_params.get("budget_duration") is not None:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -217,3 +217,45 @@ async def test_provider_budget_boundary_is_unchanged(
|
|||
)
|
||||
|
||||
assert (kept != []) is expected_kept
|
||||
|
||||
|
||||
def test_zero_max_budget_without_duration_initializes_router_budget_limiter() -> None:
|
||||
"""A configured zero budget must not be skipped by a truthiness check."""
|
||||
assert RouterBudgetLimiting.should_init_router_budget_limiter(
|
||||
provider_budget_config=None,
|
||||
model_list=[{"litellm_params": {"max_budget": 0}}],
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("scope", ["provider", "deployment", "tag"])
|
||||
async def test_none_max_budget_does_not_block_spend(disable_budget_sync, scope: str) -> None:
|
||||
"""An unset budget retains the existing non-blocking behaviour."""
|
||||
limiter = RouterBudgetLimiting(dual_cache=DualCache(), provider_budget_config=None)
|
||||
deployment = _deployment()
|
||||
provider_configs: dict[str, BudgetConfig] = {}
|
||||
deployment_configs: dict[str, BudgetConfig] = {}
|
||||
deployment_providers: list[str | None] = []
|
||||
request_tags: list[str] = []
|
||||
|
||||
if scope == "provider":
|
||||
provider_configs = {"openai": _budget(limit=None)}
|
||||
deployment_providers = ["openai"]
|
||||
elif scope == "deployment":
|
||||
deployment_configs = {"deployment-1": _budget(limit=None)}
|
||||
else:
|
||||
limiter.tag_budget_config = {"prod": _budget(limit=None)}
|
||||
request_tags = ["prod"]
|
||||
|
||||
kept, blocked_info = limiter._filter_out_deployments_above_budget(
|
||||
potential_deployments=[],
|
||||
healthy_deployments=[deployment],
|
||||
provider_configs=provider_configs,
|
||||
deployment_configs=deployment_configs,
|
||||
deployment_providers=deployment_providers,
|
||||
spend_map={},
|
||||
request_tags=request_tags,
|
||||
)
|
||||
|
||||
assert kept == [deployment]
|
||||
assert blocked_info == ""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue