File tree 1 file changed +4
-4
lines changed
1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -97,8 +97,7 @@ stream = client.chat.completions.create(
97
97
stream = True ,
98
98
)
99
99
for chunk in stream:
100
- if chunk.choices[0 ].delta.content is not None :
101
- print (chunk.choices[0 ].delta.content)
100
+ print (chunk.choices[0 ].delta.content or " " , end = " " )
102
101
```
103
102
104
103
The async client uses the exact same interface.
@@ -108,15 +107,16 @@ from openai import AsyncOpenAI
108
107
109
108
client = AsyncOpenAI()
110
109
110
+
111
111
async def main ():
112
112
stream = await client.chat.completions.create(
113
113
model = " gpt-4" ,
114
114
messages = [{" role" : " user" , " content" : " Say this is a test" }],
115
115
stream = True ,
116
116
)
117
117
async for chunk in stream:
118
- if chunk.choices[0 ].delta.content is not None :
119
- print (chunk.choices[ 0 ].delta.content)
118
+ print ( chunk.choices[0 ].delta.content or " " , end = " " )
119
+
120
120
121
121
asyncio.run(main())
122
122
```
You can’t perform that action at this time.
0 commit comments