Skip to content

Commit e1a6d90

Browse files
author
Richard Kennedy
committed
Change SDK to use cai_add_default_manifest instead of sign_with_cai
This commit also updates the usage of the proto enums relating to CAI.
1 parent 1dd9d49 commit e1a6d90

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/stability_sdk/api.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def generate(
122122
guidance_strength: float = 0.0,
123123
preset: Optional[str] = None,
124124
return_request: bool = False,
125-
sign_with_cai: bool = False,
125+
cai_add_default_manifest: bool = False,
126126
) -> Dict[int, List[Any]]:
127127
"""
128128
Generate an image from a set of weighted prompts.
@@ -165,7 +165,7 @@ def generate(
165165
start_schedule = 1.0 - init_strength
166166
image_params = self._build_image_params(width, height, sampler, steps, seed, samples, cfg_scale,
167167
start_schedule, init_noise_scale, masked_area_init,
168-
guidance_preset, guidance_cuts, guidance_strength, sign_with_cai)
168+
guidance_preset, guidance_cuts, guidance_strength, cai_add_default_manifest)
169169

170170
extras = Struct()
171171
if preset and preset.lower() != 'none':
@@ -236,7 +236,7 @@ def inpaint(
236236
start_schedule = 1.0-init_strength
237237
image_params = self._build_image_params(width, height, sampler, steps, seed, samples, cfg_scale,
238238
start_schedule, init_noise_scale, masked_area_init,
239-
guidance_preset, guidance_cuts, guidance_strength, sign_with_cai=False)
239+
guidance_preset, guidance_cuts, guidance_strength, cai_add_default_manifest=False)
240240

241241
extras = Struct()
242242
if preset and preset.lower() != 'none':
@@ -539,7 +539,7 @@ def _adjust_request_for_retry(self, request: generation.Request, attempt: int):
539539

540540
def _build_image_params(self, width, height, sampler, steps, seed, samples, cfg_scale,
541541
schedule_start, init_noise_scale, masked_area_init,
542-
guidance_preset, guidance_cuts, guidance_strength, sign_with_cai):
542+
guidance_preset, guidance_cuts, guidance_strength, cai_add_default_manifest):
543543

544544
if not seed:
545545
seed = [random.randrange(0, 4294967295)]
@@ -571,10 +571,10 @@ def _build_image_params(self, width, height, sampler, steps, seed, samples, cfg_
571571
)
572572
# empty CAI Parameters will result in images not being signed by the CAI server
573573
caip = generation.CAIParameters()
574-
if sign_with_cai:
574+
if cai_add_default_manifest:
575575
caip = generation.CAIParameters(
576576
model_metadata=generation._CAIPARAMETERS_MODELMETADATA.values_by_name[
577-
'SIGN_WITH_ENGINE_ID'].number)
577+
'MODEL_METADATA_SIGN_WITH_ENGINE_ID'].number)
578578

579579
return generation.ImageParameters(
580580
transform=None if sampler is None else generation.TransformType(diffusion=sampler),

src/stability_sdk/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ def process_cli(logger: logging.Logger = None,
499499
"--width", "-W", type=int, default=512, help="[512] width of image"
500500
)
501501
parser_generate.add_argument(
502-
"--sign_with_cai", type=bool, default=False, help="Sign artifacts using C2PA to include providence data containing engine id"
502+
"--cai_add_default_manifest", type=bool, default=False, help="Attatch a signed manifest to artifacts using C2PA. The default manifest will contain engine id and publisher name (Stability AI)"
503503
)
504504
parser_generate.add_argument(
505505
"--start_schedule",
@@ -634,7 +634,7 @@ def process_cli(logger: logging.Logger = None,
634634
"samples": args.num_samples,
635635
"init_image": args.init_image,
636636
"mask_image": args.mask_image,
637-
"sign_with_cai": args.sign_with_cai,
637+
"cai_add_default_manifest": args.cai_add_default_manifest,
638638
}
639639

640640
if args.sampler:

tests/test_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,17 @@ def test_api_generate_cai_signing_set():
103103
class CAIMockStub(MockStub):
104104
def Generate(self, request: generation.Request, **kwargs) -> Generator[generation.Answer, None, None]:
105105
assert request.image.cai_parameters.model_metadata == \
106-
generation._CAIPARAMETERS_MODELMETADATA.values_by_name['SIGN_WITH_ENGINE_ID'].number
106+
generation._CAIPARAMETERS_MODELMETADATA.values_by_name['MODEL_METADATA_SIGN_WITH_ENGINE_ID'].number
107107
return super().Generate(request, **kwargs)
108108
api = Context(stub=CAIMockStub())
109109
width, height = 512, 768
110-
results = api.generate(prompts=["foo bar"], weights=[1.0], width=width, height=height, sign_with_cai=True)
110+
results = api.generate(prompts=["foo bar"], weights=[1.0], width=width, height=height, cai_add_default_manifest=True)
111111

112112
def test_api_generate_cai_signing_unset():
113113
class CAIMockStub(MockStub):
114114
def Generate(self, request: generation.Request, **kwargs) -> Generator[generation.Answer, None, None]:
115115
assert request.image.cai_parameters.model_metadata == \
116-
generation._CAIPARAMETERS_MODELMETADATA.values_by_name['METADATA_UNSPECIFIED'].number
116+
generation._CAIPARAMETERS_MODELMETADATA.values_by_name['MODEL_METADATA_UNSPECIFIED'].number
117117
return super().Generate(request, **kwargs)
118118
api = Context(stub=CAIMockStub())
119119
width, height = 512, 768

0 commit comments

Comments
 (0)