mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-13 08:52:02 +00:00
fix(router): honor explicit priority=0 in acompletion instead of falling back to default
This commit is contained in:
parent
93b5ca9612
commit
1a03bfba50
2 changed files with 47 additions and 1 deletions
|
|
@ -1850,7 +1850,7 @@ class Router:
|
|||
kwargs["original_function"] = self._acompletion
|
||||
|
||||
self._update_kwargs_before_fallbacks(model=model, kwargs=kwargs)
|
||||
request_priority = kwargs.get("priority") or self.default_priority
|
||||
request_priority = kwargs.get("priority", self.default_priority)
|
||||
start_time = time.time()
|
||||
_is_prompt_management_model = self._is_prompt_management_model(model)
|
||||
|
||||
|
|
|
|||
|
|
@ -5304,3 +5304,49 @@ class TestRouterRequestTimeoutPropagation:
|
|||
)
|
||||
== 60
|
||||
)
|
||||
|
||||
|
||||
def _make_priority_router(default_priority):
|
||||
router = litellm.Router(
|
||||
model_list=[
|
||||
{
|
||||
"model_name": "gpt-3.5-turbo",
|
||||
"litellm_params": {"model": "gpt-3.5-turbo"},
|
||||
}
|
||||
],
|
||||
default_priority=default_priority,
|
||||
)
|
||||
router.schedule_acompletion = AsyncMock(return_value="scheduled")
|
||||
router.async_function_with_fallbacks = AsyncMock(return_value="fallbacks")
|
||||
return router
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_acompletion_honors_explicit_priority_zero():
|
||||
"""priority=0 must route through the scheduler, not be dropped by an `or` default."""
|
||||
router = _make_priority_router(default_priority=None)
|
||||
|
||||
result = await router.acompletion(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
priority=0,
|
||||
)
|
||||
|
||||
assert result == "scheduled"
|
||||
router.schedule_acompletion.assert_awaited_once()
|
||||
router.async_function_with_fallbacks.assert_not_awaited()
|
||||
assert router.schedule_acompletion.await_args.kwargs["priority"] == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_acompletion_missing_priority_falls_back_to_default():
|
||||
router = _make_priority_router(default_priority=None)
|
||||
|
||||
result = await router.acompletion(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
)
|
||||
|
||||
assert result == "fallbacks"
|
||||
router.async_function_with_fallbacks.assert_awaited_once()
|
||||
router.schedule_acompletion.assert_not_awaited()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue