diff --git a/README.md b/README.md index 9311b477a3..fcf65e65b5 100644 --- a/README.md +++ b/README.md @@ -373,19 +373,28 @@ Nested parameters are dictionaries, typed using `TypedDict`, for example: ```python from openai import OpenAI +from pydantic import BaseModel client = OpenAI() -response = client.chat.responses.create( +class CalendarEvent(BaseModel): + name: str + date: str + participants: list[str] + +response = client.responses.parse( + model="gpt-4o-2024-08-06", input=[ + {"role": "system", "content": "Extract the event information."}, { "role": "user", - "content": "How much ?", - } + "content": "Alice and Bob are going to a science fair on Friday.", + }, ], - model="gpt-4o", - response_format={"type": "json_object"}, + text_format=CalendarEvent, ) + +event = response.output_parsed ``` ## File uploads