-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fix responses API #8880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix responses API #8880
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the fix!
tool_calls = [] | ||
reasoning_contents = [] | ||
|
||
for output_item in response.output: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Maybe add a comment that even though the output field of the responses API is a list, all output items belong to a single choice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
elif output_item_type == "function_call": | ||
tool_calls.append(output_item.model_dump()) | ||
elif output_item_type == "reasoning": | ||
if getattr(output_item, "content", None) and len(output_item.content) > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: is it possible that output_item
does not have content
attribute when the item type is reasoning
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically it's possible that either content or summary is unset, but again OpenAI is doing an odd job documenting Responses API.
if getattr(output_item, "content", None) and len(output_item.content) > 0: | ||
for content_item in output_item.content: | ||
reasoning_contents.append(content_item.text) | ||
elif getattr(output_item, "summary", None) and len(output_item.summary) > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
Responses API always return one choice instead of multiple choice. This is a very confusing behavior without clear documentation, but basically all items in the
output
in Response object map to one choice.