Repository navigation
feat(py/bedrock)!: typed Stability image config and model refs - #6977
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the Amazon Bedrock plugin's image generation configuration by replacing the generic, open BedrockImageConfig with strict, typed config classes for each model family: TitanImageConfig, NovaCanvasConfig, and StabilityImageConfig. This change enables local validation of parameters (such as image dimensions and quality) and allows the Dev UI to render these fields as a form. The documentation, implementation, and tests have been updated to support these new schemas. Feedback on the changes suggests dynamically extracting model fields from the passed config instance in build_amazon_image_body rather than relying on a static set based on NovaCanvasConfig, which improves maintainability if the configurations diverge in the future.
3888a6d to
2175943
Compare
d02f19f to
a7b312a
Compare
Also update README to three families, fix number_of_images, and fix stable-image-inpaint hint.
Bedrock retired Titan Image v2 on 2026-06-30 and Nova Canvas on 2026-09-30; both now fail with ResourceNotFoundException. Drop NovaCanvasConfig, TitanImageConfig, Bedrock.nova_canvas(), Bedrock.titan_image() and their Known* literals. The raw IDs still route to InvokeModel under an extra-only config, so anyone with residual access sends the body through config['extra']; the plugin builds only taskType and textToImageParams.text. The ref constructors point those IDs at the raw form.
…ed max Route non-text-to-image stability.* IDs (after stripping inference-profile prefixes and ARNs) to a dedicated stability_service ref route so text(), stability(), and embedding() all refuse editing and upscale IDs with a text-to-image-only message instead of steering to Bedrock.text(). Widen StabilityImageConfig.seed upper bound from 4294967294 to 4294967295 for Stable Image Core and Ultra, documenting SD 3.5's 4294967294 cap.
8ee570b to
ab2e974
Compare
Stacked on #7049.
Bedrock image models took an untyped dict.
BedrockImageConfigdeclared no fields and allowed any key, so a typo likeaspectRatioforaspect_ratiowas merged into the body unchecked, and an image-config typo was silently dropped (Jacob's comment on #6644). Stability now has a typed config class with flat snake_case fields, andBedrockgets typed refs named after Bedrock's output modalities (Bedrock.text,Bedrock.stabilityfor IMAGE,Bedrock.embedder) that bind each model to its config class. Unknown keys raise.extra(added in #6644) is the only way to send raw AWS body fields.Titan Image and Nova Canvas were retired on Bedrock (Titan Image v2 on 2026-06-30, Nova Canvas on 2026-09-30) and aren't typed; anyone with residual access passes the raw model ID with
config['extra'].Ref constructors, classmethods on
Bedrock; each takes a bare orbedrock/-prefixed ID and an optional defaultconfig:Bedrock.text(name) -> ModelRef[BedrockConfig]: Bedrock's TEXT output modality, served over Converse, including models that take image or document input. Unknown IDs are accepted; autocomplete comes from the text catalogBedrock.stability(name) -> ModelRef[StabilityImageConfig]: SD 3.5, Stable Image Core, Stable Image UltraBedrock.embedder(name) -> EmbedderRef: forai.embed(), mirroringGoogleAI.embedder. Noconfigparameter: Bedrock embedders ignore per-request options today, so it would be dropped silentlyConfig class, exported from
genkit_amazon_bedrock:StabilityImageConfig:aspect_ratio(the 9 AWS ratios),seed(0-4294967295; SD 3.5 caps at 4294967294),negative_prompt(max 10,000 chars),output_format(png|jpeg|webp;webpis SD 3.5 only),extraDecisions
ResourceNotFoundException, so typed classes and refs for them would be new public API for dead models. Their IDs still route to InvokeModel under a privateextra-only config: the plugin buildstaskTypeandtextToImageParams.text, and everything else comes fromconfig['extra'].Bedrock.text('amazon.nova-canvas-v1:0')says so and names the raw form.generate(config=...)and the Dev UI form validate against it, and aBedrockConfigsent to a Stability model fails Genkit's class check. The old reason for an open schema (families take different keys) no longer applies.resolve's order and with the sameimage_family()it uses. A ref'sconfig_schemais therefore always the class its action registers,us.profiles and model ARNs route as they do at runtime, and an opaque application inference profile ARN (no model ID in it) is text-only, as it is at runtime. An embedding ID only ever becomes anEmbedderRef, so it can't reachgenerate(model=...). Same shape asOpenAI.gpt/Anthropic.claude, with Google's refuse-other-families rule.extrais the only path to the AWS body. Stability no longer merges the whole config dict, and Titan/Nova no longer read a nestedimageGenerationConfig. Undeclared settings go inextra, which keeps fix(py/bedrock, py/vertexai)!: unlisted Bedrock settings go in extra; Model Garden rejects a per-request key #6644's deep merge and prompt-field rejection unchanged.GenkitConfig, likeVeoConfig; generic knobs raise.GenkitConfiggives the same camelCase aliases andextra='forbid'asModelConfig, withouttemperature,top_p,max_output_tokens,top_k,stop_sequencesorversion. Bedrock's image APIs take none of those knobs, so they now raise as unknown keys instead of being accepted and dropped, and the Dev UI form shows only real image fields.BedrockConfigstays onModelConfig, since text models use them. A Stability call with no config sends the same body as before.Breaking
BedrockImageConfigis removed (it was never exported from the package root). UseStabilityImageConfig.INVALID_ARGUMENTinstead of being sent. Move them toextra.config={'imageGenerationConfig': {...}}raisesINVALID_ARGUMENT; send it asconfig={'extra': {'imageGenerationConfig': {...}}}. The plugin no longer fills inimageGenerationConfigdefaults for these IDs ({'numberOfImages': 1, 'height': 1024, 'width': 1024, 'cfgScale': 8.0, 'seed': 0}, plus'quality': 'standard'on Nova Canvas), so Bedrock applies its own.temperature,top_p,max_output_tokens,top_k,stop_sequences) on an image model raiseINVALID_ARGUMENTinstead of being ignored. Drop them from image calls.output_formattakes lowercasepng|jpeg|webponly; other spellings go throughextra.config['extra']on an image model now fails Genkit's config check and raises, instead of coming back onresponse.error.