Skip to content

Commit dfe1c8d

Browse files
ssojoodistainless-bot
authored andcommitted
docs: small Improvement in the async chat response code (#959)
1 parent 790df76 commit dfe1c8d

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

Diff for: README.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,17 @@ from openai import AsyncOpenAI
108108

109109
client = AsyncOpenAI()
110110

111-
stream = await client.chat.completions.create(
112-
model="gpt-4",
113-
messages=[{"role": "user", "content": "Say this is a test"}],
114-
stream=True,
115-
)
116-
async for chunk in stream:
117-
if chunk.choices[0].delta.content is not None:
118-
print(chunk.choices[0].delta.content)
111+
async def main():
112+
stream = await client.chat.completions.create(
113+
model="gpt-4",
114+
messages=[{"role": "user", "content": "Say this is a test"}],
115+
stream=True,
116+
)
117+
async for chunk in stream:
118+
if chunk.choices[0].delta.content is not None:
119+
print(chunk.choices[0].delta.content)
120+
121+
asyncio.run(main())
119122
```
120123

121124
## Module-level client

0 commit comments

Comments
 (0)