openai-multi-client icon indicating copy to clipboard operation
openai-multi-client copied to clipboard

Async calls using new SDK by OpenAI

Open rafayaar opened this issue 1 year ago • 0 comments

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.

rafayaar avatar Jan 11 '24 03:01 rafayaar