mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-29 06:33:28 +00:00
parent
f277f1e260
commit
7a23e497bd
2 changed files with 47 additions and 1 deletions
|
|
@ -6062,7 +6062,7 @@ def completion(
|
|||
custom_llm_provider=custom_llm_provider,
|
||||
model_id=optional_params.get("model_id"),
|
||||
)
|
||||
if mock_response or mock_tool_calls or mock_timeout:
|
||||
if mock_response is not None or mock_tool_calls or mock_timeout:
|
||||
kwargs.pop("mock_timeout", None) # remove for any fallbacks triggered
|
||||
return mock_completion(
|
||||
model,
|
||||
|
|
|
|||
46
tests/unit/test_empty_mock_response.py
Normal file
46
tests/unit/test_empty_mock_response.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
import litellm
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mock_response", ["", "Hello"])
|
||||
@pytest.mark.parametrize("stream", [False, True])
|
||||
def test_completion_mock_response(mock_response: str, stream: bool) -> None:
|
||||
with patch("httpx.Client.send", side_effect=AssertionError("Unexpected HTTP request")):
|
||||
response = litellm.completion(
|
||||
model="openai/gpt-4o-mini",
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
mock_response=mock_response,
|
||||
stream=stream,
|
||||
)
|
||||
if stream:
|
||||
content = "".join(chunk.choices[0].delta.content or "" for chunk in response)
|
||||
else:
|
||||
content = response.choices[0].message.content
|
||||
assert content == mock_response
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("mock_response", ["", "Hello"])
|
||||
@pytest.mark.parametrize("stream", [False, True])
|
||||
async def test_acompletion_mock_response(mock_response: str, stream: bool) -> None:
|
||||
with (
|
||||
patch(
|
||||
"httpx.AsyncClient.send",
|
||||
side_effect=AssertionError("Unexpected HTTP request"),
|
||||
),
|
||||
patch("httpx.Client.send", side_effect=AssertionError("Unexpected HTTP request")),
|
||||
):
|
||||
response = await litellm.acompletion(
|
||||
model="openai/gpt-4o-mini",
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
mock_response=mock_response,
|
||||
stream=stream,
|
||||
)
|
||||
if stream:
|
||||
content = "".join([chunk.choices[0].delta.content or "" async for chunk in response])
|
||||
else:
|
||||
content = response.choices[0].message.content
|
||||
assert content == mock_response
|
||||
Loading…
Add table
Reference in a new issue