You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/openai/resources/beta/chat/completions.py
+12-6
Original file line number
Diff line number
Diff line change
@@ -78,14 +78,17 @@ def parse(
78
78
from pydantic import BaseModel
79
79
from openai import OpenAI
80
80
81
+
81
82
class Step(BaseModel):
82
83
explanation: str
83
84
output: str
84
85
86
+
85
87
class MathResponse(BaseModel):
86
88
steps: List[Step]
87
89
final_answer: str
88
90
91
+
89
92
client = OpenAI()
90
93
completion = client.beta.chat.completions.parse(
91
94
model="gpt-4o-2024-08-06",
@@ -184,12 +187,12 @@ def stream(
184
187
185
188
```py
186
189
with client.beta.chat.completions.stream(
187
-
model='gpt-4o-2024-08-06',
190
+
model="gpt-4o-2024-08-06",
188
191
messages=[...],
189
192
) as stream:
190
193
for event in stream:
191
-
if event.type == 'content.delta':
192
-
print(event.content, flush=True, end='')
194
+
if event.type == "content.delta":
195
+
print(event.content, flush=True, end="")
193
196
```
194
197
195
198
When the context manager is entered, a `ChatCompletionStream` instance is returned which, like `.create(stream=True)` is an iterator. The full list of events that are yielded by the iterator are outlined in [these docs](https://github.com/openai/openai-python/blob/main/helpers.md#chat-completions-events).
When the context manager is entered, an `AsyncChatCompletionStream` instance is returned which, like `.create(stream=True)` is an async iterator. The full list of events that are yielded by the iterator are outlined in [these docs](https://github.com/openai/openai-python/blob/main/helpers.md#chat-completions-events).
0 commit comments