(QOL improvement) Provider budget routing - allow using 1s, 1d, 1mo, 2mo etc (#6885)

* use 1 file for duration_in_seconds

* add to readme.md

* re use duration_in_seconds

* fix importing _extract_from_regex, get_last_day_of_month

* fix import

* update provider budget routing

* fix - remove dup test
This commit is contained in:
Ishaan Jaff 2024-11-23 16:59:46 -08:00 committed by GitHub
parent e69678a9b3
commit 34bfebe470
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 149 additions and 142 deletions

View file

@ -142,23 +142,6 @@ async def test_provider_budgets_e2e_test_expect_to_fail():
assert "Exceeded budget for provider" in str(exc_info.value)
def test_get_ttl_seconds():
"""
Test the get_ttl_seconds helper method"
"""
provider_budget = ProviderBudgetLimiting(
router_cache=DualCache(), provider_budget_config={}
)
assert provider_budget.get_ttl_seconds("1d") == 86400 # 1 day in seconds
assert provider_budget.get_ttl_seconds("7d") == 604800 # 7 days in seconds
assert provider_budget.get_ttl_seconds("30d") == 2592000 # 30 days in seconds
with pytest.raises(ValueError, match="Unsupported time period format"):
provider_budget.get_ttl_seconds("1h")
def test_get_llm_provider_for_deployment():
"""
Test the _get_llm_provider_for_deployment helper method

View file

@ -17,7 +17,7 @@ import pytest
import litellm
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, headers
from litellm.proxy.utils import (
_duration_in_seconds,
duration_in_seconds,
_extract_from_regex,
get_last_day_of_month,
)
@ -593,7 +593,7 @@ def test_duration_in_seconds():
duration_until_next_month = next_month - current_time
expected_duration = int(duration_until_next_month.total_seconds())
value = _duration_in_seconds(duration="1mo")
value = duration_in_seconds(duration="1mo")
assert value - expected_duration < 2