Skip to content

Commit a269014

Browse files
Copilotowndev
andcommitted
Restrict ImageConfig to Gemini 3 models only
- Added _check_image_config_support() method to identify Gemini 3 image models - Updated _check_image_generation_support() to include Gemini 3 image models - Modified _configure_generation() to only apply ImageConfig for Gemini 3 models - Updated documentation to clarify ImageConfig is only for Gemini 3 models - Added model compatibility table showing which models support ImageConfig - Gemini 2.5 image models still support image generation but use defaults Co-authored-by: owndev <69784886+owndev@users.noreply.github.com>
1 parent 1ebd248 commit a269014

2 files changed

Lines changed: 81 additions & 31 deletions

File tree

docs/google-gemini-integration.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ GOOGLE_IMAGE_HISTORY_FIRST=true
128128
# Default: true
129129
GOOGLE_IMAGE_UPLOAD_FALLBACK=true
130130

131-
# Image generation configuration (for image-capable models like gemini-2.5-flash-image-preview)
131+
# Image generation configuration (only for Gemini 3 image models like gemini-3-pro-image-preview)
132+
# Note: These settings do not apply to Gemini 2.5 image models
132133
# Default aspect ratio for generated images
133134
# Valid values: "1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9"
134135
# Default: "1:1"
@@ -212,7 +213,10 @@ VERTEX_AI_RAG_STORE="projects/your-project/locations/global/collections/default_
212213
213214
## Image Generation Configuration
214215

215-
The Google Gemini pipeline supports configurable aspect ratios and resolutions for image generation with image-capable models (e.g., `gemini-2.5-flash-image-preview`).
216+
The Google Gemini pipeline supports configurable aspect ratios and resolutions for image generation with **Gemini 3 image models** (e.g., `gemini-3-pro-image-preview`, `gemini-3-flash-image-preview`).
217+
218+
> [!IMPORTANT]
219+
> **Model Compatibility**: The `aspect_ratio` and `image_size` parameters (ImageConfig) are **only supported by Gemini 3 image models**. Gemini 2.5 image models (e.g., `gemini-2.5-flash-image-preview`) support image generation but do not support these configuration parameters. When using Gemini 2.5 image models, default aspect ratio and resolution will be used automatically.
216220
217221
### Aspect Ratio
218222

@@ -263,9 +267,9 @@ from google.genai import types
263267

264268
client = genai.Client(api_key="your-api-key")
265269

266-
# Generate a 4K widescreen image
270+
# Generate a 4K widescreen image with Gemini 3
267271
response = client.models.generate_content(
268-
model="gemini-2.5-flash-image-preview",
272+
model="gemini-3-pro-image-preview",
269273
contents="A serene mountain landscape at sunset",
270274
config=types.GenerateContentConfig(
271275
response_modalities=["TEXT", "IMAGE"],
@@ -304,6 +308,16 @@ for part in response.parts:
304308
- TikTok content
305309
- Mobile app screens
306310

311+
### Model Compatibility
312+
313+
| Model | ImageConfig Support (aspect_ratio, image_size) |
314+
| ------------------------- | ----------------------------------------------- |
315+
| gemini-3-pro-image-\* | ✅ Supported |
316+
| gemini-3-flash-image-\* | ✅ Supported |
317+
| gemini-2.5-flash-image-\* | ❌ Not supported (uses defaults) |
318+
| Other gemini-3-\* models | ❌ Not image generation models |
319+
| Other models | ❌ Not image generation models |
320+
307321
## Web search and access
308322

309323
[Grounding with Google search](https://ai.google.dev/gemini-api/docs/google-search) together with the [URL context tool](https://ai.google.dev/gemini-api/docs/url-context) are enabled/disabled together via the `google_search_tool` feature, which can be switched on/off in a Filter.

pipelines/google/google_gemini.py

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -739,10 +739,12 @@ def _check_image_generation_support(self, model_id: str) -> bool:
739739
Returns:
740740
True if the model supports image generation, False otherwise
741741
"""
742-
# Known image generation models
742+
# Known image generation models (both Gemini 2.5 and Gemini 3)
743743
image_generation_models = [
744744
"gemini-2.5-flash-image-preview",
745745
"gemini-2.5-flash-image",
746+
"gemini-3-pro-image-preview",
747+
"gemini-3-flash-image-preview",
746748
]
747749

748750
# Check for exact matches or pattern matches
@@ -758,6 +760,29 @@ def _check_image_generation_support(self, model_id: str) -> bool:
758760

759761
return False
760762

763+
def _check_image_config_support(self, model_id: str) -> bool:
764+
"""
765+
Check if a model supports ImageConfig (aspect_ratio and image_size parameters).
766+
767+
ImageConfig is only supported by Gemini 3 image generation models.
768+
Gemini 2.5 image models support image generation but not ImageConfig.
769+
770+
Args:
771+
model_id: The model ID to check
772+
773+
Returns:
774+
True if the model supports ImageConfig, False otherwise
775+
"""
776+
# ImageConfig is only supported by Gemini 3 models
777+
model_lower = model_id.lower()
778+
779+
# Check if it's a Gemini 3 model
780+
if "gemini-3-" not in model_lower:
781+
return False
782+
783+
# Check if it's an image generation model
784+
return self._check_image_generation_support(model_id)
785+
761786
def _check_thinking_support(self, model_id: str) -> bool:
762787
"""
763788
Check if a model supports the thinking feature.
@@ -1642,34 +1667,45 @@ def _configure_generation(
16421667
gen_config_params["response_modalities"] = ["TEXT", "IMAGE"]
16431668

16441669
# Configure image generation parameters (aspect ratio and resolution)
1645-
# Body parameters override valve defaults for per-request customization
1646-
aspect_ratio = body.get(
1647-
"aspect_ratio", self.valves.IMAGE_GENERATION_ASPECT_RATIO
1648-
)
1649-
resolution = body.get("image_size", self.valves.IMAGE_GENERATION_RESOLUTION)
1670+
# ImageConfig is only supported by Gemini 3 models
1671+
if self._check_image_config_support(model_id):
1672+
# Body parameters override valve defaults for per-request customization
1673+
aspect_ratio = body.get(
1674+
"aspect_ratio", self.valves.IMAGE_GENERATION_ASPECT_RATIO
1675+
)
1676+
resolution = body.get(
1677+
"image_size", self.valves.IMAGE_GENERATION_RESOLUTION
1678+
)
16501679

1651-
# Validate and normalize the values
1652-
validated_aspect_ratio = self._validate_aspect_ratio(aspect_ratio)
1653-
validated_resolution = self._validate_resolution(resolution)
1680+
# Validate and normalize the values
1681+
validated_aspect_ratio = self._validate_aspect_ratio(aspect_ratio)
1682+
validated_resolution = self._validate_resolution(resolution)
16541683

1655-
# Create image config if we have valid values
1656-
if validated_aspect_ratio and validated_resolution:
1657-
try:
1658-
gen_config_params["image_config"] = types.ImageConfig(
1659-
aspect_ratio=validated_aspect_ratio,
1660-
image_size=validated_resolution,
1661-
)
1662-
self.log.debug(
1663-
f"Image generation config: aspect_ratio={validated_aspect_ratio}, resolution={validated_resolution}"
1664-
)
1665-
except (AttributeError, TypeError) as e:
1666-
# Fall back if SDK does not support ImageConfig
1667-
self.log.warning(
1668-
f"ImageConfig not supported by SDK version: {e}. Image generation will use default settings."
1669-
)
1670-
except Exception as e:
1671-
# Log unexpected errors but continue without image config
1672-
self.log.warning(f"Unexpected error configuring ImageConfig: {e}")
1684+
# Create image config if we have valid values
1685+
if validated_aspect_ratio and validated_resolution:
1686+
try:
1687+
gen_config_params["image_config"] = types.ImageConfig(
1688+
aspect_ratio=validated_aspect_ratio,
1689+
image_size=validated_resolution,
1690+
)
1691+
self.log.debug(
1692+
f"Image generation config: aspect_ratio={validated_aspect_ratio}, resolution={validated_resolution}"
1693+
)
1694+
except (AttributeError, TypeError) as e:
1695+
# Fall back if SDK does not support ImageConfig
1696+
self.log.warning(
1697+
f"ImageConfig not supported by SDK version: {e}. Image generation will use default settings."
1698+
)
1699+
except Exception as e:
1700+
# Log unexpected errors but continue without image config
1701+
self.log.warning(
1702+
f"Unexpected error configuring ImageConfig: {e}"
1703+
)
1704+
else:
1705+
self.log.debug(
1706+
f"Model {model_id} does not support ImageConfig (aspect_ratio/resolution). "
1707+
"ImageConfig is only available for Gemini 3 image models."
1708+
)
16731709

16741710
# Configure Gemini thinking/reasoning for models that support it
16751711
# This is independent of include_thoughts - thinking config controls HOW the model reasons,

0 commit comments

Comments
 (0)