@@ -122,6 +122,7 @@ def generate(
122
122
guidance_strength : float = 0.0 ,
123
123
preset : Optional [str ] = None ,
124
124
return_request : bool = False ,
125
+ sign_with_cai : bool = False ,
125
126
) -> Dict [int , List [Any ]]:
126
127
"""
127
128
Generate an image from a set of weighted prompts.
@@ -164,7 +165,7 @@ def generate(
164
165
start_schedule = 1.0 - init_strength
165
166
image_params = self ._build_image_params (width , height , sampler , steps , seed , samples , cfg_scale ,
166
167
start_schedule , init_noise_scale , masked_area_init ,
167
- guidance_preset , guidance_cuts , guidance_strength )
168
+ guidance_preset , guidance_cuts , guidance_strength , sign_with_cai )
168
169
169
170
extras = Struct ()
170
171
if preset and preset .lower () != 'none' :
@@ -235,7 +236,7 @@ def inpaint(
235
236
start_schedule = 1.0 - init_strength
236
237
image_params = self ._build_image_params (width , height , sampler , steps , seed , samples , cfg_scale ,
237
238
start_schedule , init_noise_scale , masked_area_init ,
238
- guidance_preset , guidance_cuts , guidance_strength )
239
+ guidance_preset , guidance_cuts , guidance_strength , sign_with_cai = False )
239
240
240
241
extras = Struct ()
241
242
if preset and preset .lower () != 'none' :
@@ -538,7 +539,7 @@ def _adjust_request_for_retry(self, request: generation.Request, attempt: int):
538
539
539
540
def _build_image_params (self , width , height , sampler , steps , seed , samples , cfg_scale ,
540
541
schedule_start , init_noise_scale , masked_area_init ,
541
- guidance_preset , guidance_cuts , guidance_strength ):
542
+ guidance_preset , guidance_cuts , guidance_strength , sign_with_cai ):
542
543
543
544
if not seed :
544
545
seed = [random .randrange (0 , 4294967295 )]
@@ -568,6 +569,12 @@ def _build_image_params(self, width, height, sampler, steps, seed, samples, cfg_
568
569
)
569
570
]
570
571
)
572
+ # empty CAI Parameters will result in images not being signed by the CAI server
573
+ caip = generation .CAIParameters ()
574
+ if sign_with_cai :
575
+ caip = generation .CAIParameters (
576
+ model_metadata = generation ._CAIPARAMETERS_MODELMETADATA .values_by_name [
577
+ 'SIGN_WITH_ENGINE_ID' ].number )
571
578
572
579
return generation .ImageParameters (
573
580
transform = None if sampler is None else generation .TransformType (diffusion = sampler ),
@@ -578,6 +585,7 @@ def _build_image_params(self, width, height, sampler, steps, seed, samples, cfg_
578
585
samples = samples ,
579
586
masked_area_init = masked_area_init ,
580
587
parameters = [generation .StepParameter (** step_parameters )],
588
+ cai_parameters = caip
581
589
)
582
590
583
591
def _process_response (self , response ) -> Dict [int , List [Any ]]:
0 commit comments