fix(vertex_ai/gemini): fix Gemini MIME detection for extensionless GCS URIs (addresses Greptile feedback on #27278) - #27713
Closed
krrish-berri-2 wants to merge 1 commit into
Conversation
…S URIs Addresses Greptile feedback on PR #27278: 1. Add GCS object metadata lookup via Storage JSON API for extensionless gs:// URIs — falls back gracefully when metadata is unavailable 2. Use asyncify() to offload the sync httpx.get call in async_transform_request_body so it does not block the event loop 3. Add MIME type normalization and validation via _normalize_and_validate_gemini_mime_type 4. Propagate litellm_params (vertex_project/vertex_credentials) through _transform_messages → _gemini_convert_messages_with_history so private GCS objects can be authenticated 5. Accept mime_type/content_type as aliases for format in image_url and file content blocks 6. All new tests use proper mocks — no real outbound HTTP in the test suite Co-authored-by: Krrish Dholakia <krrish-berri-2@users.noreply.github.com>
|
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relevant issues
Addresses Greptile feedback on PR #27278 (Fix Gemini MIME detection for extensionless GCS URIs).
Pre-Submission checklist
tests/test_litellm/directorymake test-unitType
🐛 Bug Fix
✅ Test
Changes
This PR implements the changes from PR #27278 with all Greptile-identified issues resolved:
Issues Fixed (from Greptile score 3/5)
Event-loop blocking —
async_transform_request_bodywas calling_transform_request_bodysynchronously, which in turn calls_get_gcs_object_content_type(up to 5s synchttpx.get). Fixed by wrapping withasyncify()to offload to a thread pool worker.Unmocked test making real HTTP calls — All tests now mock
_get_gcs_object_content_typeso no real outbound requests are made tostorage.googleapis.com.Core Feature (from PR #27278)
_get_gcs_object_content_typeresolves MIME type from GCS Storage JSON API for extensionlessgs://URIslitellm_paramspropagation:vertex_project/vertex_credentialsare threaded from request body through_transform_messages→_gemini_convert_messages_with_history→_process_gemini_media→_get_gcs_object_content_type_normalize_and_validate_gemini_mime_typenormalizes aliases (e.g.,image/jpg→image/jpeg) and validates against Gemini's accepted file typesmime_type/content_typeaccepted as aliases forformatinimage_urlandfilecontent blocksTests Added (12 new tests, all mock-only)
image/jpg→image/jpeg)mime_typefieldAffected files
litellm/llms/vertex_ai/gemini/transformation.pylitellm/llms/gemini/chat/transformation.pylitellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.pytests/test_litellm/llms/vertex_ai/test_vertex.py