mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
feat: Add gemini-3-pro-image-preview model support for imageSize parameters (#17019)
- Add model identifier to FLASH_IMAGE_PREVIEW_MODEL_IDENTIFIERS - Add imageSize parameter support (1K, 2K, 4K) with GeminiImageSize type - Add tests for imageSize parameter transformation - Update documentation with new model
This commit is contained in:
parent
a727f71b19
commit
be970735de
5 changed files with 45 additions and 4 deletions
|
|
@ -224,8 +224,8 @@ asyncio.run(generate_image())
|
|||
|
||||
| Provider | Model |
|
||||
|----------|--------|
|
||||
| Google AI Studio | `gemini/gemini-2.0-flash-preview-image-generation`, `gemini/gemini-2.5-flash-image-preview` |
|
||||
| Vertex AI | `vertex_ai/gemini-2.0-flash-preview-image-generation`, `vertex_ai/gemini-2.5-flash-image-preview` |
|
||||
| Google AI Studio | `gemini/gemini-2.0-flash-preview-image-generation`, `gemini/gemini-2.5-flash-image-preview`, `gemini/gemini-3-pro-image-preview` |
|
||||
| Vertex AI | `vertex_ai/gemini-2.0-flash-preview-image-generation`, `vertex_ai/gemini-2.5-flash-image-preview`, `vertex_ai/gemini-3-pro-image-preview` |
|
||||
|
||||
## Spec
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ FLASH_IMAGE_PREVIEW_MODEL_IDENTIFIERS = (
|
|||
"2.0-flash-preview-image",
|
||||
"2.0-flash-preview-image-generation",
|
||||
"2.5-flash-image-preview",
|
||||
"3-pro-image-preview",
|
||||
)
|
||||
class GoogleImageGenConfig(BaseImageGenerationConfig):
|
||||
DEFAULT_BASE_URL: str = "https://generativelanguage.googleapis.com/v1beta"
|
||||
|
|
@ -75,7 +76,7 @@ class GoogleImageGenConfig(BaseImageGenerationConfig):
|
|||
"1792x1024": "16:9",
|
||||
"1024x1792": "9:16",
|
||||
"1280x896": "4:3",
|
||||
"896x1280": "3:4"
|
||||
"896x1280": "3:4",
|
||||
}
|
||||
return aspect_ratio_map.get(size, "1:1")
|
||||
|
||||
|
|
|
|||
|
|
@ -183,8 +183,13 @@ GeminiResponseModalities = Literal["TEXT", "IMAGE", "AUDIO", "VIDEO"]
|
|||
|
||||
GeminiImageAspectRatio = Literal["1:1", "2:3", "3:2", "3:4", "4:3", "9:16", "16:9", "21:9"]
|
||||
|
||||
GeminiImageSize = Literal["1K", "2K", "4K"]
|
||||
|
||||
|
||||
class GeminiImageConfig(TypedDict, total=False):
|
||||
aspectRatio: GeminiImageAspectRatio
|
||||
imageSize: GeminiImageSize
|
||||
|
||||
|
||||
class PrebuiltVoiceConfig(TypedDict):
|
||||
voiceName: str
|
||||
|
|
|
|||
|
|
@ -191,4 +191,38 @@ async def test__transform_request_body_image_config_snake_case():
|
|||
|
||||
assert "generationConfig" in rb
|
||||
assert "image_config" in rb["generationConfig"]
|
||||
assert rb["generationConfig"]["image_config"] == {"aspect_ratio": "16:9"}
|
||||
assert rb["generationConfig"]["image_config"] == {"aspect_ratio": "16:9"}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test__transform_request_body_image_config_with_image_size():
|
||||
"""Test imageSize parameter support in imageConfig"""
|
||||
model = "gemini-3-pro-image-preview"
|
||||
messages = [
|
||||
{
|
||||
"role": "user",
|
||||
"content": [
|
||||
{"type": "text", "text": "Generate a 4K image of Tokyo skyline"}
|
||||
]
|
||||
}
|
||||
]
|
||||
optional_params = {
|
||||
"imageConfig": {"aspectRatio": "16:9", "imageSize": "4K"},
|
||||
"responseModalities": ["Image"]
|
||||
}
|
||||
litellm_params = {}
|
||||
transform_request_params = {
|
||||
"messages": messages,
|
||||
"model": model,
|
||||
"optional_params": optional_params,
|
||||
"custom_llm_provider": "gemini",
|
||||
"litellm_params": litellm_params,
|
||||
"cached_content": None,
|
||||
}
|
||||
|
||||
rb: RequestBody = transformation._transform_request_body(**transform_request_params)
|
||||
|
||||
assert "generationConfig" in rb
|
||||
assert "imageConfig" in rb["generationConfig"]
|
||||
assert rb["generationConfig"]["imageConfig"]["aspectRatio"] == "16:9"
|
||||
assert rb["generationConfig"]["imageConfig"]["imageSize"] == "4K"
|
||||
|
|
@ -295,6 +295,7 @@ def test_gemini_image_generation():
|
|||
[
|
||||
"gemini/gemini-2.5-flash-image-preview",
|
||||
"gemini/gemini-2.0-flash-preview-image-generation",
|
||||
"gemini/gemini-3-pro-image-preview",
|
||||
],
|
||||
)
|
||||
def test_gemini_flash_image_preview_models(model_name: str):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue