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
Confirm this is an issue with the Python library and not an underlying OpenAI API
This is an issue with the Python library
Describe the bug
When I use a Pydantic model in response.parse, it works fine in synchronous mode. But in asynchronous mode, I get an error.
See test code below.
To Reproduce
The code to reproduce the issue is below.
When the code is run, the synchronous version of response.parse returns a correct response. The asynchronous version results in this error:
AttributeError Traceback (most recent call last)
File ~/projects/pdf_summarizer/.venv/lib/python3.12/site-packages/openai/lib/_parsing/_responses.py:62, in parse_response(text_format, input_tools, response)
59 solved_t = solve_response_format_t(text_format)
60 output_list: List[ParsedResponseOutputItem[TextFormatT]] = []
---> 62 for output in response.output:
63 if output.type == "message":
64 content_list: List[ParsedContent[TextFormatT]] = []
AttributeError: 'str' object has no attribute 'output'
Code snippets
importjsonfromtypingimportListimportopenaifrompydanticimportBaseModelimportpytestclassCalendarEvent(BaseModel):
name: strdate: strparticipants: List[str]
deftest_response_parse_sync():
client=openai.OpenAI()
response=client.responses.parse(
model="gpt-4o-2024-08-06",
input=[
{"role": "system", "content": "Extract the event information."},
{"role": "user", "content": "Alice and Bob are going to a science fair on Friday."},
],
text_format=CalendarEvent,
)
returnresponseasyncdeftest_response_parse_async():
client=openai.AsyncOpenAI()
stream=awaitclient.responses.parse(
model="gpt-4o-2024-08-06",
input=[
{"role": "system", "content": "Extract the event information."},
{"role": "user", "content": "Alice and Bob are going to a science fair on Friday."},
],
text_format=CalendarEvent,
stream=True,
)
asyncforeventinstream:
print(event)
# Returns a response conforming to the Pydantic model.print(test_response_parse_sync())
# Errors out.awaittest_response_parse_async()
OS
macOS
Python version
Python v3.12
Library version
OpenAI v1.73.0
The text was updated successfully, but these errors were encountered:
Confirm this is an issue with the Python library and not an underlying OpenAI API
Describe the bug
When I use a Pydantic model in
response.parse
, it works fine in synchronous mode. But in asynchronous mode, I get an error.See test code below.
To Reproduce
The code to reproduce the issue is below.
When the code is run, the synchronous version of response.parse returns a correct response. The asynchronous version results in this error:
Code snippets
OS
macOS
Python version
Python v3.12
Library version
OpenAI v1.73.0
The text was updated successfully, but these errors were encountered: