-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Python: Add file handling support to BinaryContent for OpenAI Responses API #12258
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
base: main
Are you sure you want to change the base?
Conversation
Haven't looked yet, but why can't we use BinaryContent for this? |
Binary is meant to be abstract (mentioned in code comments). ImageContent and FileContent derive from it. It also needed mapping to match open ai api schema spec for pdf file as base64. FileContent adapts the existing ImageContent implementation. |
2a0a1f7
to
f53e50c
Compare
Hi @ltwlf, can you please check your Ruff settings? There are a lot of extra line adds and such in this PR, that aren't necessary -- most of the initial changes in I see The current code has the following following 99 chars (allowed because < 120): from openai.types.responses.response_content_part_added_event import ResponseContentPartAddedEvent and you're trying to commit the change that brings the first import line to 71 chars: from openai.types.responses.response_content_part_added_event import (
ResponseContentPartAddedEvent,
) |
991b27a
to
3da6b35
Compare
@moonbox3 thanks for the feedback and you are right about the unnecessary formatting changes. I tracked down the issue - the root .vscode/settings.json was using autopep8 instead of ruff, which caused imports to be formatted differently than the project's pyproject.toml configuration. I've fixed the VSCode settings and reverted all the unrelated formatting changes. The PR now only contains the minimal changes needed for FileContent functionality, and future contributions won't have this formatting issue. |
@ltwlf we had a chat internally, we will eventually align the design of this with the dotnet Microsoft.Extensions.AI design, which only has BinaryContent without subclasses, so we would prefer to update BinaryContent instead of introducing something new that we then have to remove again, could you adapt this PR to do that (or create a new one)? Should be mostly adapting some of the docstrings in binarycontent and then using that instead of the filecontent for OpenAI Responses! Thanks for your efforts though, much appreciated! |
73a0e0d
to
9558303
Compare
@eavanvalkenburg thanks for the feedback! To clarify, are you suggesting that the binary type should handle OpenAI file data by default, with ImageContent inheriting from binary and overriding methods specifically for image handling? |
196c926
to
bc8e221
Compare
@ltwlf exactly, eventually we might remove the ImageContent altogether, but that is breaking so we won't any time soon. |
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.
couple of small comments, overall it looks good. Do fix the linting settings because a lot of changes come from that which is annoying!
bc8e221
to
2efa0f5
Compare
Python Test Coverage Report •
Python Unit Test Overview
|
8d1f9f6
to
fbc1c12
Compare
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.
Looks great, thanks for the effort!
fb0c094
to
11ae8bf
Compare
@eavanvalkenburg now it is ready to review :) |
11ae8bf
to
8f2363f
Compare
bf8ef4b
to
c13deb9
Compare
c13deb9
to
1eed7a9
Compare
e55e7b4
to
8e1af11
Compare
I fixed some lint issues. The pre-commit hooks in my project weren’t working, so I reinstalled them. |
…nt with OpenAI Responses Agent
8e1af11
to
39f5a77
Compare
@moonbox3 – I’ve added the examples you requested. Could you take another look when you have a moment? I’m a bit concerned we might run into merge conflicts if this PR stays open much longer. Thanks! |
Summary
Enhances
BinaryContent
to support file handling for OpenAI Responses API, enabling file uploads through the responses agent while maintaining a provider-agnostic design.Changes
BinaryContent Enhancements
can_read
property: Indicates whether content has readable data availablefrom_file()
class method: Creates BinaryContent instances from file paths with automatic base64 encodingOpenAI Responses Agent Integration
responses_agent_thread_actions.py
filename
andfile_data
structure with data URI formatTesting
can_read
,from_file()
, and binary data handlingDesign Principles
Usage Example