Skip to content

Commit

Permalink
docs: small streaming readme improvements (#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored Dec 11, 2023
1 parent fb9d0a3 commit f3be2e5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ stream = client.chat.completions.create(
stream=True,
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content)
print(chunk.choices[0].delta.content or "", end="")
```

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

client = AsyncOpenAI()


async def main():
stream = await client.chat.completions.create(
model="gpt-4",
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(chunk.choices[0].delta.content)
print(chunk.choices[0].delta.content or "", end="")


asyncio.run(main())
```
Expand Down

0 comments on commit f3be2e5

Please sign in to comment.