-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: Cannot send attach file to OpenAI throw LiteLlm (Fixes #2862 ) #2863
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?
fix: Cannot send attach file to OpenAI throw LiteLlm (Fixes #2862 ) #2863
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.
Summary of Changes
Hello @Lin-Nikaido, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request resolves an issue preventing attached files from being correctly sent to OpenAI via LiteLLM. The changes enable asynchronous file uploads for OpenAI and Azure, allowing files to be referenced by a file_id
after upload, which is a more efficient and compatible method for these providers. The existing behavior for other LLM providers, where files are sent as base64 encoded data, is maintained.
Highlights
- Asynchronous File Handling: Converted key internal functions (
_content_to_message_param
,_get_content
,_get_completion_inputs
) to asynchronous operations to support file uploads and improve performance. - OpenAI/Azure File Upload via file_id: Implemented logic to upload attached files (e.g., PDFs, text files) to OpenAI/Azure using
litellm.acreate_file
and then reference them by theirfile_id
in the LLM request, rather than embedding the raw file data. - Provider-Specific File Handling: Introduced a mechanism to identify the specific LLM provider (OpenAI, Azure, Gemini, etc.) and apply the appropriate file handling strategy, ensuring
file_id
is used for OpenAI/Azure and base64 data for others. - Expanded Supported File Types: Extended the range of supported file types for attachment to include various text, document (MS Word, PowerPoint), and code file formats.
- Comprehensive Unit Tests: Added new unit tests specifically for the OpenAI
file_id
integration and updated existing tests to accommodate the new asynchronous functions and confirm correct file handling logic across different providers.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request correctly implements file attachment handling for OpenAI models via LiteLLM by uploading the file to get a file_id
. The necessary asynchronous changes and corresponding test updates are well-executed. I've identified a potential bug in the provider detection logic and an opportunity to improve code readability. The new tests effectively validate the implemented functionality.
fix typo Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Fixes #2862
This fixes
Add test code in

tests/unittests/models/test_litellm.py
and it passed.