mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
fix(vertex-ai): default missing native content roles
This commit is contained in:
parent
2a12707372
commit
103b3a9b81
2 changed files with 34 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
Loading…
Add table
Reference in a new issue