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
Structured outputs allow users to define an output scheme using pydantic. OpenAI and most others support this now (see e.g. OpenAI and their docs).
frompydanticimportBaseModelfromopenaiimportOpenAIclient=OpenAI()
classCalendarEvent(BaseModel):
name: strdate: strparticipants: list[str]
completion=client.beta.chat.completions.parse(
model="gpt-4o-2024-08-06",
messages=[
{"role": "system", "content": "Extract the event information."},
{"role": "user", "content": "Alice and Bob are going to a science fair on Friday."},
],
response_format=CalendarEvent,
)
event=completion.choices[0].message.parsed
In my own tests using scikit-ollama I found the models to adhere much better to the output scheme. It barely ever had to fall back to the default label which made it overall more accurate.
It was also usually faster.
The text was updated successfully, but these errors were encountered:
Structured outputs allow users to define an output scheme using pydantic. OpenAI and most others support this now (see e.g. OpenAI and their docs).
In my own tests using scikit-ollama I found the models to adhere much better to the output scheme. It barely ever had to fall back to the default label which made it overall more accurate.
It was also usually faster.
The text was updated successfully, but these errors were encountered: