UPDATE: Figured it out myself and put working version within code snippets, below, with help on pypi-dot-org documentation for openai version 1.3.#.
I’ve a python code that had been working just fine with OpenAI module version 0.28.1. However, after upgrading the module to version 1.3.5 and migrating my codes with the command “openai migrate”, API calls do not successfully receive response data.
Looks like the following two code snippets receive empty contents in “r.choices[0].message[“content”]” as well as each of “r_item.choices[0].delta”.
Code Snippet #1 (for non-streaming messages)
r = await aclient.chat.completions.create(model=self.model,
messages=messages,
**OPENAI_COMPLETION_OPTIONS)
doesn’t work
answer = r.choices[0].message[“content”]
working version
answer = r.messages[“content”]
Code Snippet #2 (for streaming messages)
r_gen = await aclient.chat.completions.create(model=self.model,
messages=messages,
stream=True,
**OPENAI_COMPLETION_OPTIONS)
answer = “”
async for r_item in r_gen:
doesn’t work
delta = r_item.choices[0].delta
if "content" in delta:
answer += delta.content
working version
delta = r_item.choices[0].delta.content
if delta:
answer += delta