fix(vertex-ai): default missing native content roles

This commit is contained in:
Devin AI 2026-07-10 07:06:52 +00:00
parent 2a12707372
commit 103b3a9b81
2 changed files with 34 additions and 2 deletions

View file

@ -82,10 +82,18 @@ class VertexAIGoogleGenAIConfig(GoogleGenAIConfig):
if generate_content_config_dict:
self._normalize_response_schema(generate_content_config_dict, model)
# Build the request in Google GenAI format that Vertex AI expects
vertex_contents = (
[
{**content, "role": content.get("role", "user")} if isinstance(content, dict) else content
for content in contents
]
if isinstance(contents, list)
else contents
)
result = {
"model": model,
"contents": contents,
"contents": vertex_contents,
}
# Add tools if provided

View file

@ -0,0 +1,24 @@
from litellm.llms.vertex_ai.google_genai.transformation import (
VertexAIGoogleGenAIConfig,
)
def test_transform_generate_content_request_defaults_omitted_role():
config = VertexAIGoogleGenAIConfig()
contents = [
{"parts": [{"text": "Hello"}]},
{"role": "model", "parts": [{"text": "Hi"}]},
]
result = config.transform_generate_content_request(
model="gemini-2.5-flash",
contents=contents,
tools=None,
generate_content_config_dict={},
)
assert result["contents"] == [
{"role": "user", "parts": [{"text": "Hello"}]},
{"role": "model", "parts": [{"text": "Hi"}]},
]
assert "role" not in contents[0]