Skip to content

Commit d5f8921

Browse files
committed
fix readme on nested_params for response format
1 parent 53f7a74 commit d5f8921

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,19 +373,28 @@ Nested parameters are dictionaries, typed using `TypedDict`, for example:
373373

374374
```python
375375
from openai import OpenAI
376+
from pydantic import BaseModel
376377

377378
client = OpenAI()
378379

379-
response = client.chat.responses.create(
380+
class CalendarEvent(BaseModel):
381+
name: str
382+
date: str
383+
participants: list[str]
384+
385+
response = client.responses.parse(
386+
model="gpt-4o-2024-08-06",
380387
input=[
388+
{"role": "system", "content": "Extract the event information."},
381389
{
382390
"role": "user",
383-
"content": "How much ?",
384-
}
391+
"content": "Alice and Bob are going to a science fair on Friday.",
392+
},
385393
],
386-
model="gpt-4o",
387-
response_format={"type": "json_object"},
394+
text_format=CalendarEvent,
388395
)
396+
397+
event = response.output_parsed
389398
```
390399

391400
## File uploads

0 commit comments

Comments
 (0)