Added support to additional MIME types for Gemini model
Title
Add support for additional MIME types in Gemini models
Relevant issues
Fixes #9416
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
- [x] I have Added testing in the
[tests/litellm/](https://github.com/BerriAI/litellm/tree/main/tests/litellm)directory, Adding at least 1 test is a hard requirement - [see details](https://docs.litellm.ai/docs/extras/contributing_code) - [x] I have added a screenshot of my new test passing locally
- [ ] My PR passes all unit tests on (
make test-unit)[https://docs.litellm.ai/docs/extras/contributing_code] - [x] My PR's scope is as isolated as possible, it only solves 1 specific problem
Type
🆕 New Feature
Changes
This PR adds support for non-image/PDF file types with Gemini models, specifically addressing:
- Fixed handling of text-based formats (Markdown, JSON, XML, CSV) that don't require base64 encoding
- Resolved token counting errors for text files by preventing unnecessary encoding
- Expanded MIME type detection to support additional file formats
- Maintains backward compatibility with existing image/PDF handling
Files Modified:
-
litellm/types/files.py:
- Added
requires_base64_encoding()function - Added new file types (Markdown, XML) to supported types
- Updated
GEMINI_1_5_ACCEPTED_FILE_TYPESto include text-based formats
- Added
-
litellm/llms/vertex_ai/gemini/transformation.py:
- Renamed
_process_gemini_image()to_process_gemini_file() - Added conditional logic to handle text files without base64 encoding
- Expanded
_get_mime_type_from_url()to detect additional formats - Fixed typo in error message ("filr" → "file")
- Updated function references
- Renamed
Files Created:
-
tests/litellm/llms/vertex_ai/gemini/test_transformation.py:
- Added tests for MIME type detection
- Added tests for text vs binary file handling
- Added tests for file type validation
Images:
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| litellm | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Mar 27, 2025 9:00pm |
@NiharP31 I see that this PR is stale for a few months. Do you plan to fix the conflicts so that it can be merged? Does it support Gemini 2.5 models?
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.