refactor(openai.py): making it compatible for openai v1

BREAKING CHANGE:
This commit is contained in:
Krrish Dholakia 2023-11-11 15:32:14 -08:00
parent a861dd69c9
commit a5ec85b1f2
12 changed files with 622 additions and 370 deletions

View file

@ -28,15 +28,13 @@ def test_async_response():
user_message = "Hello, how are you?"
messages = [{"content": user_message, "role": "user"}]
try:
response = await acompletion(model="gpt-3.5-turbo", messages=messages)
print(f"response: {response}")
response = await acompletion(model="azure/chatgpt-v-2", messages=messages)
response = await acompletion(model="gpt-3.5-turbo-instruct", messages=messages)
print(f"response: {response}")
except Exception as e:
pytest.fail(f"An exception occurred: {e}")
response = asyncio.run(test_get_response())
# print(response)
print(response)
# test_async_response()
def test_get_response_streaming():
@ -45,8 +43,7 @@ def test_get_response_streaming():
user_message = "write a short poem in one sentence"
messages = [{"content": user_message, "role": "user"}]
try:
response = await acompletion(model="azure/chatgpt-v-2", messages=messages, stream=True)
# response = await acompletion(model="gpt-3.5-turbo", messages=messages, stream=True)
response = await acompletion(model="gpt-3.5-turbo-instruct", messages=messages, stream=True)
print(type(response))
import inspect
@ -59,18 +56,17 @@ def test_get_response_streaming():
async for chunk in response:
token = chunk["choices"][0]["delta"].get("content", "")
output += token
print(f"output: {output}")
assert output is not None, "output cannot be None."
assert isinstance(output, str), "output needs to be of type str"
assert len(output) > 0, f"Length of output needs to be greater than 0. {output}"
assert len(output) > 0, "Length of output needs to be greater than 0."
print(f'output: {output}')
except Exception as e:
pytest.fail(f"An exception occurred: {e}")
return response
asyncio.run(test_async_call())
test_get_response_streaming()
# test_get_response_streaming()
def test_get_response_non_openai_streaming():
import asyncio