Issue with structured output, 'parse' not working correctly: 'Beta' object has no attribute Chat & 'Completions' object has no attribute 'parse'

I was working on building a data model this morning and ran into issues using structured outputs using Pydantic model. This doesn’t seem to necessarily be a python issue – this is also very closely related to api documentation / prior implementation.

Does anyone know of a potential fix, or if this is a bug?

Steps to reproduce / pseudo code:

from pydantic import BaseModel
from openai import OpenAI

client = OpenAI()


class RawResponse(BaseModel):
    answer: str


input_data = "..."

completion = client.beta.chat.completions.parse( 
    model="gpt-4o-2024-08-06",
    messages=[
        {
            "role": "system", 
            "content": 
                (
                    "You will be given unstructured text, please convert it into the given structure."
                )
        },
        {
            "role": "user", "content": f"{input_data}"}
    ],
    response_format=RawResponse,
)

event = completion.choices[0].message.parsed

1 Like

This will likely be remedied by updating the OpenAI module with pip to the latest version, and ensuring you don’t have different user, system-installed, and venv versions being used unpredictably.

The methods are those of the Python library, not endpoint.

1 Like