mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
test(batch): make the upstream-failure tolerance actually reachable
batch_completion collects per-request failures into its result list rather than raising them; its own source says "return exceptions if any". So the test's `except Timeout` and `except litellm.InternalServerError` arms could never fire for the case they were written for. An upstream 500 instead reached `response.choices`, raised AttributeError on the exception object, and fell through to the bare `except Exception` that calls pytest.fail. That is what CircleCI hit. The tolerance now reads the returned values, which is where the failures actually are. The same two exception types are tolerated as before, nothing broader. Checked against four injected outcomes: three InternalServerErrors pass, three Timeouts pass, an AuthenticationError fails, and a response whose content is None fails. So it is not tolerating its way to a vacuous green.
This commit is contained in:
parent
d8679508d4
commit
e8b9f3675b
1 changed files with 21 additions and 21 deletions
|
|
@ -19,32 +19,32 @@ from litellm import (
|
|||
# litellm.set_verbose=True
|
||||
|
||||
|
||||
TOLERATED_UPSTREAM_FAILURES = (Timeout, litellm.InternalServerError)
|
||||
|
||||
|
||||
def test_batch_completions():
|
||||
messages = [[{"role": "user", "content": "write a short poem"}] for _ in range(3)]
|
||||
model = "gpt-3.5-turbo"
|
||||
litellm.set_verbose = True
|
||||
try:
|
||||
result = batch_completion(
|
||||
model=model,
|
||||
messages=messages,
|
||||
max_tokens=10,
|
||||
temperature=0.2,
|
||||
request_timeout=1,
|
||||
)
|
||||
print(result)
|
||||
print(len(result))
|
||||
assert len(result) == 3
|
||||
|
||||
for response in result:
|
||||
assert response.choices[0].message.content is not None
|
||||
except Timeout as e:
|
||||
print(f"IN TIMEOUT")
|
||||
pass
|
||||
except litellm.InternalServerError as e:
|
||||
print(f"IN INTERNAL SERVER ERROR")
|
||||
pass
|
||||
except Exception as e:
|
||||
pytest.fail(f"An error occurred: {e}")
|
||||
result = batch_completion(
|
||||
model=model,
|
||||
messages=messages,
|
||||
max_tokens=10,
|
||||
temperature=0.2,
|
||||
request_timeout=1,
|
||||
)
|
||||
print(result)
|
||||
|
||||
assert len(result) == 3
|
||||
|
||||
for response in result:
|
||||
if isinstance(response, TOLERATED_UPSTREAM_FAILURES):
|
||||
continue
|
||||
assert not isinstance(
|
||||
response, Exception
|
||||
), f"batch_completion returned {type(response).__name__}: {response}"
|
||||
assert response.choices[0].message.content is not None
|
||||
|
||||
|
||||
# test_batch_completions()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue