Commit dfe1c8da

Sahand Sojoodi <ssojoodi@gmail.com>
2023-12-10 04:16:52
docs: small Improvement in the async chat response code (#959)
1 parent 790df76
Changed files (1)
README.md
@@ -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