mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
fix(router): keep deployments when provider budget has duration but no max_budget
This commit is contained in:
parent
69a491e168
commit
8a87909a3f
2 changed files with 55 additions and 13 deletions
|
|
@ -222,20 +222,21 @@ class RouterBudgetLimiting(CustomLogger):
|
|||
provider = self._get_llm_provider_for_deployment(deployment)
|
||||
if provider in provider_configs:
|
||||
config = provider_configs[provider]
|
||||
if config.max_budget is None:
|
||||
continue
|
||||
current_spend = spend_map.get(f"provider_spend:{provider}:{config.budget_duration}", 0.0)
|
||||
self._track_provider_remaining_budget_prometheus(
|
||||
provider=provider,
|
||||
spend=current_spend,
|
||||
budget_limit=config.max_budget,
|
||||
)
|
||||
if config.max_budget is not None:
|
||||
current_spend = spend_map.get(f"provider_spend:{provider}:{config.budget_duration}", 0.0)
|
||||
self._track_provider_remaining_budget_prometheus(
|
||||
provider=provider,
|
||||
spend=current_spend,
|
||||
budget_limit=config.max_budget,
|
||||
)
|
||||
|
||||
if config.max_budget and current_spend >= config.max_budget:
|
||||
debug_msg = f"Exceeded budget for provider {provider}: {current_spend} >= {config.max_budget}"
|
||||
deployment_above_budget_info += f"{debug_msg}\n"
|
||||
is_within_budget = False
|
||||
continue
|
||||
if current_spend >= config.max_budget:
|
||||
debug_msg = (
|
||||
f"Exceeded budget for provider {provider}: {current_spend} >= {config.max_budget}"
|
||||
)
|
||||
deployment_above_budget_info += f"{debug_msg}\n"
|
||||
is_within_budget = False
|
||||
continue
|
||||
|
||||
# Check deployment budget
|
||||
if self.deployment_budget_config and is_within_budget:
|
||||
|
|
|
|||
|
|
@ -141,6 +141,47 @@ async def test_async_filter_deployments_resolves_provider_once_per_deployment(
|
|||
assert provider_resolution_calls == len(healthy_deployments)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_async_filter_deployments_keeps_provider_without_max_budget(
|
||||
disable_budget_sync, monkeypatch
|
||||
):
|
||||
provider_budget = RouterBudgetLimiting(
|
||||
dual_cache=DualCache(),
|
||||
provider_budget_config={
|
||||
"openai": BudgetConfig(budget_duration="1d"),
|
||||
},
|
||||
)
|
||||
|
||||
healthy_deployments = [
|
||||
{
|
||||
"model_name": "gpt-4o-mini",
|
||||
"litellm_params": {"model": "openai/gpt-4o-mini"},
|
||||
"model_info": {"id": "deployment-1"},
|
||||
},
|
||||
{
|
||||
"model_name": "gpt-4o-mini",
|
||||
"litellm_params": {"model": "openai/gpt-4o-mini"},
|
||||
"model_info": {"id": "deployment-2"},
|
||||
},
|
||||
]
|
||||
|
||||
monkeypatch.setattr(
|
||||
provider_budget,
|
||||
"_get_llm_provider_for_deployment",
|
||||
lambda deployment: "openai",
|
||||
)
|
||||
|
||||
filtered_deployments = await provider_budget.async_filter_deployments(
|
||||
model="gpt-4o-mini",
|
||||
healthy_deployments=healthy_deployments,
|
||||
messages=[],
|
||||
request_kwargs={},
|
||||
parent_otel_span=None,
|
||||
)
|
||||
|
||||
assert filtered_deployments == healthy_deployments
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_async_filter_deployments_does_not_recompute_provider_when_resolved_none(
|
||||
disable_budget_sync, monkeypatch
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue