mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
Added test
Signed-off-by: Soumik Sarker <ronodhirsoumik@gmail.com>
This commit is contained in:
parent
dd8f3624d4
commit
5b38173041
1 changed files with 31 additions and 0 deletions
|
|
@ -35,6 +35,15 @@ def _chat_response() -> Dict[str, Any]:
|
|||
}
|
||||
|
||||
|
||||
def _error_response() -> Dict[str, Any]:
|
||||
return {
|
||||
"result": None,
|
||||
"success": False,
|
||||
"errors": [{"code": 7003, "message": "Could not route"}],
|
||||
"messages": [],
|
||||
}
|
||||
|
||||
|
||||
def _streaming_chunks() -> list[str]:
|
||||
return [
|
||||
json.dumps({"response": "I am"}),
|
||||
|
|
@ -145,3 +154,25 @@ def test_completion_cloudflare_stream(sync_mode):
|
|||
if c.choices[0].delta.content
|
||||
)
|
||||
assert "language" in content.lower()
|
||||
|
||||
|
||||
def test_completion_cloudflare_api_error():
|
||||
messages = [{"role": "user", "content": "what llm are you"}]
|
||||
mock_resp = _make_mock_response(_error_response())
|
||||
# Setting to a 200 HTTP code because Cloudflare returns standard HTTP OK even when it wraps error JSONs.
|
||||
mock_resp.status_code = 200
|
||||
|
||||
import litellm
|
||||
|
||||
with patch.object(HTTPHandler, "post", return_value=mock_resp) as mock_post:
|
||||
with pytest.raises(litellm.exceptions.APIConnectionError) as exc_info:
|
||||
completion(
|
||||
model="cloudflare/@cf/meta/llama-2-7b-chat-int8",
|
||||
messages=messages,
|
||||
max_tokens=15,
|
||||
api_base=FAKE_API_BASE,
|
||||
api_key=FAKE_API_KEY,
|
||||
)
|
||||
|
||||
mock_post.assert_called_once()
|
||||
assert "7003" in str(exc_info.value)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue