Skip to content

Commit 02a1e38

Browse files
committed
Remove * unpackng
Change-Id: Iddc42b906dfab12dfa500f0f9774d58521684548
1 parent dfecd12 commit 02a1e38

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

google/generativeai/vision_models/_vision_models.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,19 @@ def to_mapping_value(value) -> struct_pb2.Struct:
9191
# We got a dict (or something dict-like); convert it.
9292
return struct_pb2.Struct(fields={k: to_value(v) for k, v in value.items()})
9393

94-
ASPECT_RATIOS = ["1:1", "9:16", "16:9", "4:3", "3:4"]
95-
OUTPUT_MIME_TYPES = ["image/png", "image/jpeg"]
96-
SAFETY_FILTER_LEVELS = ["block_most", "block_some", "block_few", "block_fewest"]
97-
PERSON_GENERATIONS = ["dont_allow", "allow_adult", "allow_all"]
94+
95+
AspectRatio = Literal["1:1", "9:16", "16:9", "4:3", "3:4"]
96+
ASPECT_RATIOS = AspectRatio.__args__
97+
98+
OutputMimeType = Literal["image/png", "image/jpeg"]
99+
OUTPUT_MIME_TYPES = OutputMimeType.__args__
100+
101+
SafetyFilterLevel = Literal["block_most", "block_some", "block_few", "block_fewest"]
102+
SAFETY_FILTER_LEVELS = SafetyFilterLevel.__args__
103+
104+
PersonGeneration = Literal["dont_allow", "allow_adult", "allow_all"]
105+
PERSON_GENERATIONS = PersonGeneration.__args__
106+
98107

99108
class Image:
100109
"""Image."""
@@ -226,15 +235,13 @@ def _generate_images(
226235
number_of_images: int = 1,
227236
width: Optional[int] = None,
228237
height: Optional[int] = None,
229-
aspect_ratio: Optional[Literal[*ASPECT_RATIOS]] = None,
238+
aspect_ratio: Optional[AspectRatio] = None,
230239
guidance_scale: Optional[float] = None,
231-
output_mime_type: Optional[Literal[*OUTPUT_MIME_TYPES]] = None,
240+
output_mime_type: Optional[OutputMimeType] = None,
232241
compression_quality: Optional[float] = None,
233242
language: Optional[str] = None,
234-
safety_filter_level: Optional[
235-
Literal[*SAFETY_FILTER_LEVELS]
236-
] = None,
237-
person_generation: Optional[Literal[*PERSON_GENERATIONS]] = None,
243+
safety_filter_level: Optional[SafetyFilterLevel] = None,
244+
person_generation: Optional[PersonGeneration] = None,
238245
) -> "ImageGenerationResponse":
239246
"""Generates images from text prompt.
240247
@@ -292,7 +299,7 @@ def _generate_images(
292299
max_size = max(width or 0, height or 0) or None
293300
if aspect_ratio is not None:
294301
if aspect_ratio not in ASPECT_RATIOS:
295-
raise ValueError(f'aspect_ratio not in {ASPECT_RATIOS}')
302+
raise ValueError(f"aspect_ratio not in {ASPECT_RATIOS}")
296303
parameters["aspectRatio"] = aspect_ratio
297304
elif max_size:
298305
# Note: The size needs to be a string
@@ -316,7 +323,7 @@ def _generate_images(
316323
parameters["outputOptions"] = {}
317324
if output_mime_type is not None:
318325
if output_mime_type not in OUTPUT_MIME_TYPES:
319-
raise ValueError(f'output_mime_type not in {OUTPUT_MIME_TYPES}')
326+
raise ValueError(f"output_mime_type not in {OUTPUT_MIME_TYPES}")
320327
parameters["outputOptions"]["mimeType"] = output_mime_type
321328
shared_generation_parameters["mime_type"] = output_mime_type
322329

@@ -326,7 +333,7 @@ def _generate_images(
326333

327334
if safety_filter_level is not None:
328335
if safety_filter_level not in SAFETY_FILTER_LEVELS:
329-
raise ValueError(f'safety_filter_level not in {SAFETY_FILTER_LEVELS}')
336+
raise ValueError(f"safety_filter_level not in {SAFETY_FILTER_LEVELS}")
330337
parameters["safetySetting"] = safety_filter_level
331338
shared_generation_parameters["safety_filter_level"] = safety_filter_level
332339

@@ -361,13 +368,13 @@ def generate_images(
361368
*,
362369
negative_prompt: Optional[str] = None,
363370
number_of_images: int = 1,
364-
aspect_ratio: Optional[Literal["1:1", "9:16", "16:9", "4:3", "3:4"]] = None,
371+
aspect_ratio: Optional[AspectRatio] = None,
365372
guidance_scale: Optional[float] = None,
366373
language: Optional[str] = None,
367374
safety_filter_level: Optional[
368-
Literal["block_most", "block_some", "block_few", "block_fewest"]
375+
SafetyFilterLevel
369376
] = None,
370-
person_generation: Optional[Literal["dont_allow", "allow_adult", "allow_all"]] = None,
377+
person_generation: Optional[PersonGeneration] = None,
371378
) -> "ImageGenerationResponse":
372379
"""Generates images from text prompt.
373380

0 commit comments

Comments
 (0)