26
26
GeminiPart ,
27
27
GeminiMimeType ,
28
28
)
29
- from comfy_api_nodes .apis .gemini_api import GeminiImageGenerationConfig , GeminiImageGenerateContentRequest
29
+ from comfy_api_nodes .apis .gemini_api import GeminiImageGenerationConfig , GeminiImageGenerateContentRequest , GeminiImageConfig
30
30
from comfy_api_nodes .apis .client import (
31
31
ApiEndpoint ,
32
32
HttpMethod ,
@@ -63,6 +63,7 @@ class GeminiImageModel(str, Enum):
63
63
"""
64
64
65
65
gemini_2_5_flash_image_preview = "gemini-2.5-flash-image-preview"
66
+ gemini_2_5_flash_image = "gemini-2.5-flash-image"
66
67
67
68
68
69
def get_gemini_endpoint (
@@ -538,7 +539,7 @@ def INPUT_TYPES(cls) -> InputTypeDict:
538
539
{
539
540
"tooltip" : "The Gemini model to use for generating responses." ,
540
541
"options" : [model .value for model in GeminiImageModel ],
541
- "default" : GeminiImageModel .gemini_2_5_flash_image_preview .value ,
542
+ "default" : GeminiImageModel .gemini_2_5_flash_image .value ,
542
543
},
543
544
),
544
545
"seed" : (
@@ -579,6 +580,14 @@ def INPUT_TYPES(cls) -> InputTypeDict:
579
580
# "tooltip": "How many images to generate",
580
581
# },
581
582
# ),
583
+ "aspect_ratio" : (
584
+ IO .COMBO ,
585
+ {
586
+ "tooltip" : "Defaults to matching the output image size to that of your input image, or otherwise generates 1:1 squares." ,
587
+ "options" : ["auto" , "1:1" , "2:3" , "3:2" , "3:4" , "4:3" , "4:5" , "5:4" , "9:16" , "16:9" , "21:9" ],
588
+ "default" : "auto" ,
589
+ },
590
+ ),
582
591
},
583
592
"hidden" : {
584
593
"auth_token" : "AUTH_TOKEN_COMFY_ORG" ,
@@ -600,15 +609,17 @@ async def api_call(
600
609
images : Optional [IO .IMAGE ] = None ,
601
610
files : Optional [list [GeminiPart ]] = None ,
602
611
n = 1 ,
612
+ aspect_ratio : str = "auto" ,
603
613
unique_id : Optional [str ] = None ,
604
614
** kwargs ,
605
615
):
606
- # Validate inputs
607
616
validate_string (prompt , strip_whitespace = True , min_length = 1 )
608
- # Create parts list with text prompt as the first part
609
617
parts : list [GeminiPart ] = [create_text_part (prompt )]
610
618
611
- # Add other modal parts
619
+ if not aspect_ratio :
620
+ aspect_ratio = "auto" # for backward compatability with old workflows; to-do remove this in December
621
+ image_config = GeminiImageConfig (aspectRatio = aspect_ratio )
622
+
612
623
if images is not None :
613
624
image_parts = create_image_parts (images )
614
625
parts .extend (image_parts )
@@ -625,7 +636,8 @@ async def api_call(
625
636
),
626
637
],
627
638
generationConfig = GeminiImageGenerationConfig (
628
- responseModalities = ["TEXT" ,"IMAGE" ]
639
+ responseModalities = ["TEXT" ,"IMAGE" ],
640
+ imageConfig = None if aspect_ratio == "auto" else image_config ,
629
641
)
630
642
),
631
643
auth_kwargs = kwargs ,
0 commit comments