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