Skip to content

Commit f3be2e5

Browse files
docs: small streaming readme improvements (#962)
1 parent fb9d0a3 commit f3be2e5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ stream = client.chat.completions.create(
9797
stream=True,
9898
)
9999
for chunk in stream:
100-
if chunk.choices[0].delta.content is not None:
101-
print(chunk.choices[0].delta.content)
100+
print(chunk.choices[0].delta.content or "", end="")
102101
```
103102

104103
The async client uses the exact same interface.
@@ -108,15 +107,16 @@ from openai import AsyncOpenAI
108107

109108
client = AsyncOpenAI()
110109

110+
111111
async def main():
112112
stream = await client.chat.completions.create(
113113
model="gpt-4",
114114
messages=[{"role": "user", "content": "Say this is a test"}],
115115
stream=True,
116116
)
117117
async for chunk in stream:
118-
if chunk.choices[0].delta.content is not None:
119-
print(chunk.choices[0].delta.content)
118+
print(chunk.choices[0].delta.content or "", end="")
119+
120120

121121
asyncio.run(main())
122122
```

0 commit comments

Comments
 (0)