fix: Remove display_name for non-Vertex file uploads #1211
+106
−2
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.
Description
When using the Google.GenAI backend (GEMINI_API), file uploads fail if the
file_data
orinline_data
parts of the request contain adisplay_name
. The Gemini API (non-Vertex) does not support this attribute, causing aValueError
.This commit updates the
_preprocess_request
method in theGemini
class to sanitize the request. It now iterates through all content parts and setsdisplay_name
toNone
if the determined backend isGEMINI_API
. This ensures compatibility, similar to the existing handling of thelabels
attribute.Fixes #1182
Testing Plan
1. Unit Tests
test_preprocess_request_handles_backend_specific_fields
totests/unittests/models/test_google_llm.py
.GEMINI_API
,display_name
infile_data
andinline_data
is correctly set toNone
.VERTEX_AI
,display_name
remains unchanged.2. Manual End-to-End (E2E) Test
I manually verified the fix using
adk web
. The test was configured to use a Google AI Studio API key, which is the scenario where the bug occurs.When uploading a file, the request failed with the error:
{"error": "display_name parameter is not supported in Gemini API."}
. This confirms the bug.With the patch applied, the same file upload was processed successfully. The agent correctly analyzed the file and responded without errors.