From f3be2e5cc24988471e6cedb3e34bdfd3123edc63 Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Mon, 11 Dec 2023 10:01:08 +0000 Subject: [PATCH] docs: small streaming readme improvements (#962) --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b7f278fe53..2e95b8f581 100644 --- a/README.md +++ b/README.md @@ -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. @@ -108,6 +107,7 @@ from openai import AsyncOpenAI client = AsyncOpenAI() + async def main(): stream = await client.chat.completions.create( model="gpt-4", @@ -115,8 +115,8 @@ async def main(): 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()) ```