mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 03:34:10 +00:00
fix(main.py): fix async text completion streaming + add new tests
This commit is contained in:
parent
e212afc46c
commit
a88f07dc60
2 changed files with 41 additions and 14 deletions
|
@ -215,3 +215,30 @@ def test_get_response_non_openai_streaming():
|
|||
|
||||
|
||||
# test_get_response_non_openai_streaming()
|
||||
|
||||
|
||||
async def test_get_response():
|
||||
try:
|
||||
response = await litellm.atext_completion(
|
||||
model="gpt-3.5-turbo",
|
||||
prompt="good morning",
|
||||
stream=True,
|
||||
max_tokens=10,
|
||||
)
|
||||
print(f"response: {response}")
|
||||
|
||||
num_finish_reason = 0
|
||||
async for chunk in response:
|
||||
print(chunk)
|
||||
if chunk["choices"][0].get("finish_reason") is not None:
|
||||
num_finish_reason += 1
|
||||
print("finish_reason", chunk["choices"][0].get("finish_reason"))
|
||||
|
||||
assert (
|
||||
num_finish_reason == 1
|
||||
), f"expected only one finish reason. Got {num_finish_reason}"
|
||||
except Exception as e:
|
||||
pytest.fail(f"GOT exception for gpt-3.5 instruct In streaming{e}")
|
||||
|
||||
|
||||
# asyncio.run(test_get_response())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue