mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-24 00:52:24 +00:00
test(router): track attempted fallback groups via the mock call log
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
f0e87f2457
commit
db7d52eeda
1 changed files with 6 additions and 5 deletions
|
|
@ -3460,8 +3460,6 @@ async def test_acompletion_mid_stream_fallback_walks_every_entry_of_the_configur
|
|||
from litellm.exceptions import MidStreamFallbackError
|
||||
from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapper
|
||||
|
||||
attempted_model_groups: list[str] = []
|
||||
|
||||
class FailingStream(CustomStreamWrapper):
|
||||
def __init__(self, model: str):
|
||||
super().__init__(
|
||||
|
|
@ -3497,7 +3495,6 @@ async def test_acompletion_mid_stream_fallback_walks_every_entry_of_the_configur
|
|||
raise StopAsyncIteration from None
|
||||
|
||||
async def fake_acompletion(**kwargs):
|
||||
attempted_model_groups.append(kwargs["metadata"]["model_group"])
|
||||
if "fb2" in kwargs["model"]:
|
||||
return OkStream(kwargs["model"])
|
||||
return FailingStream(kwargs["model"])
|
||||
|
|
@ -3512,14 +3509,18 @@ async def test_acompletion_mid_stream_fallback_walks_every_entry_of_the_configur
|
|||
num_retries=0,
|
||||
)
|
||||
|
||||
with patch("litellm.acompletion", side_effect=fake_acompletion):
|
||||
with patch("litellm.acompletion", side_effect=fake_acompletion) as mock_acompletion:
|
||||
response = await router.acompletion(model="primary", messages=[{"role": "user", "content": "hi"}], stream=True)
|
||||
content: Final = "".join(
|
||||
[chunk.choices[0].delta.content or "" async for chunk in response if chunk is not None]
|
||||
)
|
||||
|
||||
assert content == "ok-from-openai/fb2-model"
|
||||
assert attempted_model_groups == ["primary", "fb1", "fb2"]
|
||||
assert [c.kwargs["metadata"]["model_group"] for c in mock_acompletion.call_args_list] == [
|
||||
"primary",
|
||||
"fb1",
|
||||
"fb2",
|
||||
]
|
||||
|
||||
|
||||
def test_refusal_on_the_last_fallback_hop_is_returned_instead_of_raised():
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue