Client.beta.chat is not working

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’

You should pip upgrade your openai library and ensure you are running python > 3.10 and the latest >1.40.0 of the OpenAI library

Similar issue here

3 Likes

thank you. I just got a change on the environments from last time I ran my code and now it is an older version of openai