mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
fix(vertex_ai): pass through native Gemini imageConfig params for image generation
aspectRatio and imageSize were silently dropped because they weren't listed in get_supported_openai_params(), so the validation layer filtered them out before they could reach transform_image_generation_request(). Fixes #21070
This commit is contained in:
parent
809838042e
commit
155bed57e8
2 changed files with 48 additions and 1 deletions
|
|
@ -43,13 +43,20 @@ class VertexAIGeminiImageGenerationConfig(BaseImageGenerationConfig, VertexLLM):
|
|||
|
||||
def get_supported_openai_params(
|
||||
self, model: str
|
||||
) -> List[OpenAIImageGenerationOptionalParams]:
|
||||
) -> list:
|
||||
"""
|
||||
Gemini image generation supported parameters
|
||||
|
||||
Includes native Gemini imageConfig params (aspectRatio, imageSize)
|
||||
in both camelCase and snake_case variants.
|
||||
"""
|
||||
return [
|
||||
"n",
|
||||
"size",
|
||||
"aspectRatio",
|
||||
"aspect_ratio",
|
||||
"imageSize",
|
||||
"image_size",
|
||||
]
|
||||
|
||||
def map_openai_params(
|
||||
|
|
@ -71,6 +78,10 @@ class VertexAIGeminiImageGenerationConfig(BaseImageGenerationConfig, VertexLLM):
|
|||
elif k == "size":
|
||||
# Map OpenAI size format to Gemini aspectRatio
|
||||
mapped_params["aspectRatio"] = self._map_size_to_aspect_ratio(v)
|
||||
elif k in ("aspectRatio", "aspect_ratio"):
|
||||
mapped_params["aspectRatio"] = v
|
||||
elif k in ("imageSize", "image_size"):
|
||||
mapped_params["imageSize"] = v
|
||||
else:
|
||||
mapped_params[k] = v
|
||||
|
||||
|
|
|
|||
|
|
@ -65,6 +65,42 @@ class TestVertexAIGeminiImageGenerationConfig:
|
|||
assert self.config._map_size_to_aspect_ratio("896x1280") == "3:4"
|
||||
assert self.config._map_size_to_aspect_ratio("unknown") == "1:1" # default
|
||||
|
||||
def test_get_supported_openai_params_includes_native_gemini_params(self):
|
||||
"""Test that native Gemini imageConfig params are supported"""
|
||||
supported = self.config.get_supported_openai_params("gemini-3-pro-image-preview")
|
||||
assert "aspectRatio" in supported
|
||||
assert "aspect_ratio" in supported
|
||||
assert "imageSize" in supported
|
||||
assert "image_size" in supported
|
||||
|
||||
def test_map_openai_params_aspect_ratio_camel_case(self):
|
||||
"""Test mapping native aspectRatio parameter"""
|
||||
result = self.config.map_openai_params(
|
||||
{"aspectRatio": "9:16"}, {}, "gemini-3-pro-image-preview", False
|
||||
)
|
||||
assert result["aspectRatio"] == "9:16"
|
||||
|
||||
def test_map_openai_params_aspect_ratio_snake_case(self):
|
||||
"""Test mapping native aspect_ratio parameter"""
|
||||
result = self.config.map_openai_params(
|
||||
{"aspect_ratio": "16:9"}, {}, "gemini-3-pro-image-preview", False
|
||||
)
|
||||
assert result["aspectRatio"] == "16:9"
|
||||
|
||||
def test_map_openai_params_image_size_camel_case(self):
|
||||
"""Test mapping native imageSize parameter"""
|
||||
result = self.config.map_openai_params(
|
||||
{"imageSize": "4K"}, {}, "gemini-3-pro-image-preview", False
|
||||
)
|
||||
assert result["imageSize"] == "4K"
|
||||
|
||||
def test_map_openai_params_image_size_snake_case(self):
|
||||
"""Test mapping native image_size parameter"""
|
||||
result = self.config.map_openai_params(
|
||||
{"image_size": "2K"}, {}, "gemini-3-pro-image-preview", False
|
||||
)
|
||||
assert result["imageSize"] == "2K"
|
||||
|
||||
def test_transform_image_generation_request_basic(self):
|
||||
"""Test basic request transformation"""
|
||||
request = self.config.transform_image_generation_request(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue