I had a code working with this method few weeks ago and now it is not working. I haven’t updated any version of openai. Now I’ve tried with the example in openai to see if it is reaaly something on my code and it is not. It is the method, not working for beta structured outputs.
CODE:
from pydantic import BaseModel
from openai import OpenAI
client = OpenAI()
class CalendarEvent(BaseModel):
name: str
date: str
participants: 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
ERROR:
AttributeError: ‘Beta’ object has no attribute ‘chat’