This commit is contained in:
Vladimir Babin 2026-10-25 08:14:30 +00:00 • committed by GitHub
commit 5941cafb4c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View file

@ -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,

View file

@ -157,6 +157,19 @@ def test_post_call_rule_rejects_mock_response(monkeypatch: pytest.MonkeyPatch) -
)
def test_completion_empty_string_mock_response_does_not_make_request() -> None:
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 == ""
def test_post_call_rule_rejects_streaming_mock_response(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(litellm, "pre_call_rules", [])
monkeypatch.setattr(litellm, "post_call_rules", [_reject_short_post_call_response])