Skip to content

Commit

Permalink
docs: small Improvement in the async chat response code (#959)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssojoodi authored Dec 9, 2023
1 parent 790df76 commit fb9d0a3
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,17 @@ from openai import AsyncOpenAI

client = AsyncOpenAI()

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)
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)

asyncio.run(main())
```

## Module-level client
Expand Down

0 comments on commit fb9d0a3

Please sign in to comment.