forked from phoenix/litellm-mirror
test(test_streaming.py): retry if openai is inconsistent with stream options
This commit is contained in:
parent
20ad1a5189
commit
207924d08f
1 changed files with 33 additions and 25 deletions
|
@ -1730,35 +1730,43 @@ def test_openai_stream_options_call():
|
||||||
|
|
||||||
def test_openai_stream_options_call_text_completion():
|
def test_openai_stream_options_call_text_completion():
|
||||||
litellm.set_verbose = False
|
litellm.set_verbose = False
|
||||||
response = litellm.text_completion(
|
for idx in range(3):
|
||||||
model="gpt-3.5-turbo-instruct",
|
try:
|
||||||
prompt="say GM - we're going to make it ",
|
response = litellm.text_completion(
|
||||||
stream=True,
|
model="gpt-3.5-turbo-instruct",
|
||||||
stream_options={"include_usage": True},
|
prompt="say GM - we're going to make it ",
|
||||||
max_tokens=10,
|
stream=True,
|
||||||
)
|
stream_options={"include_usage": True},
|
||||||
usage = None
|
max_tokens=10,
|
||||||
chunks = []
|
)
|
||||||
for chunk in response:
|
usage = None
|
||||||
print("chunk: ", chunk)
|
chunks = []
|
||||||
chunks.append(chunk)
|
for chunk in response:
|
||||||
|
print("chunk: ", chunk)
|
||||||
|
chunks.append(chunk)
|
||||||
|
|
||||||
last_chunk = chunks[-1]
|
last_chunk = chunks[-1]
|
||||||
print("last chunk: ", last_chunk)
|
print("last chunk: ", last_chunk)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Assert that:
|
Assert that:
|
||||||
- Last Chunk includes Usage
|
- Last Chunk includes Usage
|
||||||
- All chunks prior to last chunk have usage=None
|
- All chunks prior to last chunk have usage=None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert last_chunk.usage is not None
|
assert last_chunk.usage is not None
|
||||||
assert last_chunk.usage.total_tokens > 0
|
assert last_chunk.usage.total_tokens > 0
|
||||||
assert last_chunk.usage.prompt_tokens > 0
|
assert last_chunk.usage.prompt_tokens > 0
|
||||||
assert last_chunk.usage.completion_tokens > 0
|
assert last_chunk.usage.completion_tokens > 0
|
||||||
|
|
||||||
# assert all non last chunks have usage=None
|
# assert all non last chunks have usage=None
|
||||||
assert all(chunk.usage is None for chunk in chunks[:-1])
|
assert all(chunk.usage is None for chunk in chunks[:-1])
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
if idx < 2:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def test_openai_text_completion_call():
|
def test_openai_text_completion_call():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue