Skip to content

Commit 1fe3bec

Browse files
matthew29tangcopybara-github
authored andcommitted
feat: Support Imagen 4 Ingredients on Vertex
PiperOrigin-RevId: 808749595
1 parent 4193812 commit 1fe3bec

File tree

2 files changed

+90
-2
lines changed

2 files changed

+90
-2
lines changed

google/genai/tests/models/test_edit_image.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@
8787
),
8888
)
8989

90+
dog_content_ref_image = types.ContentReferenceImage(
91+
reference_id=1,
92+
reference_image=types.Image(
93+
gcs_uri='gs://genai-sdk-tests/inputs/images/dog.jpg'
94+
),
95+
)
96+
97+
cyberpunk_style_ref_image = types.StyleReferenceImage(
98+
reference_id=2,
99+
reference_image=types.Image(
100+
gcs_uri='gs://genai-sdk-tests/inputs/images/cyberpunk.jpg'
101+
),
102+
config=types.StyleReferenceConfig(
103+
style_description='cyberpunk style',
104+
),
105+
)
106+
90107
test_table: list[pytest_helper.TestTableItem] = [
91108
pytest_helper.TestTableItem(
92109
name='test_edit_mask_inpaint_insert',
@@ -176,6 +193,25 @@
176193
),
177194
),
178195
),
196+
pytest_helper.TestTableItem(
197+
name='test_edit_content_image_ingredients',
198+
exception_if_mldev='only supported in the Vertex AI client',
199+
parameters=types._EditImageParameters(
200+
model='imagen-4.0-ingredients-preview',
201+
prompt=(
202+
'Dog in [1] sleeping on the ground at the bottom of the image'
203+
' with the cyberpunk city landscape in [2] in the background'
204+
' visible on the side of the mug.'
205+
),
206+
reference_images=[dog_content_ref_image, cyberpunk_style_ref_image],
207+
config=types.EditImageConfig(
208+
number_of_images=1,
209+
aspect_ratio='9:16',
210+
include_rai_reason=True,
211+
output_mime_type='image/jpeg',
212+
),
213+
),
214+
),
179215
]
180216

181217
pytestmark = pytest_helper.setup(

google/genai/types.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6799,7 +6799,7 @@ class _EditImageParameters(_common.BaseModel):
67996799
description="""A text description of the edit to apply to the image.""",
68006800
)
68016801
reference_images: Optional[list[_ReferenceImageAPI]] = Field(
6802-
default=None, description="""The reference images for Imagen 3 editing."""
6802+
default=None, description="""The reference images for editing."""
68036803
)
68046804
config: Optional[EditImageConfig] = Field(
68056805
default=None, description="""Configuration for editing."""
@@ -6816,7 +6816,7 @@ class _EditImageParametersDict(TypedDict, total=False):
68166816
"""A text description of the edit to apply to the image."""
68176817

68186818
reference_images: Optional[list[_ReferenceImageAPIDict]]
6819-
"""The reference images for Imagen 3 editing."""
6819+
"""The reference images for editing."""
68206820

68216821
config: Optional[EditImageConfigDict]
68226822
"""Configuration for editing."""
@@ -13150,6 +13150,58 @@ class SubjectReferenceImageDict(TypedDict, total=False):
1315013150
]
1315113151

1315213152

13153+
class ContentReferenceImage(_common.BaseModel):
13154+
"""A content reference image.
13155+
13156+
A content reference image represents a subject to reference (ex. person,
13157+
product, animal) provided by the user. It can optionally be provided in
13158+
addition to a style reference image (ex. background, style reference).
13159+
"""
13160+
13161+
reference_image: Optional[Image] = Field(
13162+
default=None,
13163+
description="""The reference image for the editing operation.""",
13164+
)
13165+
reference_id: Optional[int] = Field(
13166+
default=None, description="""The id of the reference image."""
13167+
)
13168+
reference_type: Optional[str] = Field(
13169+
default=None,
13170+
description="""The type of the reference image. Only set by the SDK.""",
13171+
)
13172+
13173+
@pydantic.model_validator(mode='before')
13174+
@classmethod
13175+
def _validate_mask_image_config(self, values: Any) -> Any:
13176+
if 'reference_type' in values:
13177+
raise ValueError('Cannot set internal reference_type field directly.')
13178+
values['reference_type'] = 'REFERENCE_TYPE_CONTENT'
13179+
return values
13180+
13181+
13182+
class ContentReferenceImageDict(TypedDict, total=False):
13183+
"""A content reference image.
13184+
13185+
A content reference image represents a subject to reference (ex. person,
13186+
product, animal) provided by the user. It can optionally be provided in
13187+
addition to a style reference image (ex. background, style reference).
13188+
"""
13189+
13190+
reference_image: Optional[ImageDict]
13191+
"""The reference image for the editing operation."""
13192+
13193+
reference_id: Optional[int]
13194+
"""The id of the reference image."""
13195+
13196+
reference_type: Optional[str]
13197+
"""The type of the reference image. Only set by the SDK."""
13198+
13199+
13200+
ContentReferenceImageOrDict = Union[
13201+
ContentReferenceImage, ContentReferenceImageDict
13202+
]
13203+
13204+
1315313205
class LiveServerSetupComplete(_common.BaseModel):
1315413206
"""Sent in response to a `LiveGenerateContentSetup` message from the client."""
1315513207

0 commit comments

Comments
 (0)