-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
There are a couple of errors in the examples provided for the streaming section.
- First Issue
This is the example code, the last line should be print(chunk.choices[0].delta.content)
from openai import OpenAI
client = OpenAI()
stream = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Say this is a test"}],
stream=True,
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
print(part.choices[0].delta.content)
- Second Issue
This is the example code, the last line should be print(chunk.choices[0].delta.content)
from openai import AsyncOpenAI
client = AsyncOpenAI()
stream = await client.chat.completions.create(
prompt="Say this is a test",
messages=[{"role": "user", "content": "Say this is a test"}],
stream=True,
)
async for chunk in stream:
if chunk.choices[0].delta.content is not None:
print(part.choices[0].delta.content)
To Reproduce
If you run the snippet provided, there are None values as result
from openai import OpenAI
client = OpenAI()
stream = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Say this is a test"}],
stream=True,
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
print(part.choices[0].delta.content)+
Result:
None
None
None
None
None
None
Code snippets
No response
OS
linux
Python version
Python 3.10.12
Library version
openai v1.3.3
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working