mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-21 10:15:47 +00:00
Merge 1ecf39b9b2 into dddbaa803d
This commit is contained in:
commit
da1a4aa86f
3 changed files with 51 additions and 2 deletions
|
|
@ -6054,7 +6054,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,
|
||||
|
|
|
|||
|
|
@ -11157,7 +11157,7 @@ def should_run_mock_completion(
|
|||
mock_tool_calls: object | None,
|
||||
mock_timeout: object | None,
|
||||
) -> bool:
|
||||
if mock_response or mock_tool_calls or mock_timeout:
|
||||
if mock_response is not None or mock_tool_calls or mock_timeout:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
|
|||
49
tests/unit/test_mock_response_empty_string.py
Normal file
49
tests/unit/test_mock_response_empty_string.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import pytest
|
||||
import litellm
|
||||
from litellm.utils import should_run_mock_completion
|
||||
|
||||
|
||||
def test_should_run_mock_completion_with_empty_string():
|
||||
assert (
|
||||
should_run_mock_completion(
|
||||
mock_response="", mock_tool_calls=None, mock_timeout=None
|
||||
)
|
||||
is True
|
||||
)
|
||||
assert (
|
||||
should_run_mock_completion(
|
||||
mock_response=None, mock_tool_calls=None, mock_timeout=None
|
||||
)
|
||||
is False
|
||||
)
|
||||
assert (
|
||||
should_run_mock_completion(
|
||||
mock_response="test", mock_tool_calls=None, mock_timeout=None
|
||||
)
|
||||
is True
|
||||
)
|
||||
|
||||
|
||||
def test_completion_mock_response_empty_string():
|
||||
response = litellm.completion(
|
||||
model="openai/gpt-4o-mini",
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
mock_response="",
|
||||
api_base="http://127.0.0.1:9",
|
||||
api_key="sk-test",
|
||||
num_retries=0,
|
||||
)
|
||||
assert response.choices[0].message.content == ""
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_acompletion_mock_response_empty_string():
|
||||
response = await litellm.acompletion(
|
||||
model="openai/gpt-4o-mini",
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
mock_response="",
|
||||
api_base="http://127.0.0.1:9",
|
||||
api_key="sk-test",
|
||||
num_retries=0,
|
||||
)
|
||||
assert response.choices[0].message.content == ""
|
||||
Loading…
Add table
Reference in a new issue