Skip to content

Async calls using new SDK by OpenAI - #9

Open
rafayaar wants to merge 2 commits into
cozodb:mainfrom
rafayaar:openai-migrated-code-update
Open

Async calls using new SDK by OpenAI#9
rafayaar wants to merge 2 commits into
cozodb:mainfrom
rafayaar:openai-migrated-code-update

Conversation

@rafayaar

Copy link
Copy Markdown

Issue / Bug
Current implementation of OpenAIMultiClient is according to older version of OpenAI.
For async calls acreate function was used to do asynchronous calls.
Example from OpenAI repo:

import openai

completion = openai.ChatCompletion.acreate(model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello world"}])

When executing this MultiClient it says to migrate the code accordingly, and gives a lot of errors.
Either we can fix this by explicitly downloading earlier version of openai which is openai==0.28 or the migration I have done.

Fix

OpenAI has introduced AsyncOpenAI class through which we can handle this case
Example from OpenAI repo:

from openai import AsyncOpenAI

client = AsyncOpenAI()
completion = await client.chat.completions.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello world"}])

Calls are relatively different from previous SDK. New SDK has a lot of changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant