diff --git a/docs/DEPLOY_OPTION.md b/docs/DEPLOY_OPTION.md index c8f64a9c..2dddc814 100644 --- a/docs/DEPLOY_OPTION.md +++ b/docs/DEPLOY_OPTION.md @@ -516,6 +516,7 @@ Prompt optimization のサポート状況は [こちら](https://docs.aws.amazon "imageGenerationModelIds": [ "amazon.titan-image-generator-v2:0", "amazon.titan-image-generator-v1", + "amazon.nova-canvas-v1:0", "stability.stable-diffusion-xl-v1" ], ``` diff --git a/packages/cdk/lambda/utils/models.ts b/packages/cdk/lambda/utils/models.ts index effd4fc4..5aa424ea 100644 --- a/packages/cdk/lambda/utils/models.ts +++ b/packages/cdk/lambda/utils/models.ts @@ -4,7 +4,7 @@ import { Model, PromptTemplate, StableDiffusionParams, - TitanImageParams, + AmazonImageParams, UnrecordedMessage, ConverseInferenceParams, UsecaseConverseInferenceParams, @@ -444,7 +444,7 @@ const createBodyImageStabilityAI2024Model = (params: GenerateImageParams) => { return JSON.stringify(body); }; -const createBodyImageTitanImage = (params: GenerateImageParams) => { +const createBodyImageAmazonImage = (params: GenerateImageParams) => { // TODO: Support inpainting and outpainting too const imageGenerationConfig = { numberOfImages: 1, @@ -454,7 +454,7 @@ const createBodyImageTitanImage = (params: GenerateImageParams) => { cfgScale: params.cfgScale, seed: params.seed % 214783648, // max for titan image }; - let body: Partial = {}; + let body: Partial = {}; if (params.initImage && params.maskMode === undefined) { body = { taskType: 'IMAGE_VARIATION', @@ -552,13 +552,13 @@ const extractOutputImageStabilityAI2024Model = ( } }; -const extractOutputImageTitanImage = ( +const extractOutputImageAmazonImage = ( response: BedrockImageGenerationResponse | StabilityAI2024ModelResponse ) => { if ('images' in response) { return response.images[0]; } else { - throw new Error('Unexpected response type for Titan Image'); + throw new Error('Unexpected response type for Amazon Image'); } }; // テキスト生成に関する、各のModel のパラメーターや関数の定義 @@ -979,12 +979,16 @@ export const BEDROCK_IMAGE_GEN_MODELS: { extractOutputImage: extractOutputImageStabilityAI2024Model, }, 'amazon.titan-image-generator-v1': { - createBodyImage: createBodyImageTitanImage, - extractOutputImage: extractOutputImageTitanImage, + createBodyImage: createBodyImageAmazonImage, + extractOutputImage: extractOutputImageAmazonImage, }, 'amazon.titan-image-generator-v2:0': { - createBodyImage: createBodyImageTitanImage, - extractOutputImage: extractOutputImageTitanImage, + createBodyImage: createBodyImageAmazonImage, + extractOutputImage: extractOutputImageAmazonImage, + }, + 'amazon.nova-canvas-v1:0': { + createBodyImage: createBodyImageAmazonImage, + extractOutputImage: extractOutputImageAmazonImage, }, }; diff --git a/packages/cdk/lib/construct/api.ts b/packages/cdk/lib/construct/api.ts index c48121ef..58e73f1f 100644 --- a/packages/cdk/lib/construct/api.ts +++ b/packages/cdk/lib/construct/api.ts @@ -102,6 +102,7 @@ export class Api extends Construct { 'stability.stable-image-ultra-v1:0', 'amazon.titan-image-generator-v2:0', 'amazon.titan-image-generator-v1', + 'amazon.nova-canvas-v1:0', 'meta.llama3-8b-instruct-v1:0', 'meta.llama3-70b-instruct-v1:0', 'meta.llama3-1-8b-instruct-v1:0', diff --git a/packages/types/src/image.d.ts b/packages/types/src/image.d.ts index 5a8a5101..9c71704f 100644 --- a/packages/types/src/image.d.ts +++ b/packages/types/src/image.d.ts @@ -59,7 +59,9 @@ export type StabilityAI2024ModelParams = { // Titan Image // https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-titan-image.html -export type TitanImageParams = { +// Amazon Nova +// https://docs.aws.amazon.com/nova/latest/userguide/image-gen-access.html +export type AmazonImageParams = { taskType: 'TEXT_IMAGE' | 'INPAINTING' | 'OUTPAINTING' | 'IMAGE_VARIATION'; textToImageParams?: { text: string; diff --git a/packages/web/src/pages/GenerateImagePage.tsx b/packages/web/src/pages/GenerateImagePage.tsx index 4ce339bd..a2fb8b1b 100644 --- a/packages/web/src/pages/GenerateImagePage.tsx +++ b/packages/web/src/pages/GenerateImagePage.tsx @@ -26,9 +26,10 @@ import { GenerateImageParams } from 'generative-ai-use-cases-jp'; const MAX_SAMPLE = 7; -const TITAN_MODELS = { - V1: 'amazon.titan-image-generator-v1', - V2: 'amazon.titan-image-generator-v2:0', +const AMAZON_MODELS = { + TITAN_V1: 'amazon.titan-image-generator-v1', + TITAN_V2: 'amazon.titan-image-generator-v2:0', + NOVA_CANVAS: 'amazon.nova-canvas-v1:0', }; const STABILITY_AI_MODELS = { STABLE_DIFFUSION_XL: 'stability.stable-diffusion-xl-v1', @@ -89,7 +90,7 @@ const modelInfo: Record = { supportedModes: [GENERATION_MODES.TEXT_IMAGE], resolutionPresets: stabilityAi2024ModelPresets, }, - [TITAN_MODELS.V1]: { + [AMAZON_MODELS.TITAN_V1]: { supportedModes: [ GENERATION_MODES.TEXT_IMAGE, GENERATION_MODES.IMAGE_VARIATION, @@ -98,7 +99,16 @@ const modelInfo: Record = { ], resolutionPresets: defaultModelPresets, }, - [TITAN_MODELS.V2]: { + [AMAZON_MODELS.TITAN_V2]: { + supportedModes: [ + GENERATION_MODES.TEXT_IMAGE, + GENERATION_MODES.IMAGE_VARIATION, + GENERATION_MODES.INPAINTING, + GENERATION_MODES.OUTPAINTING, + ], + resolutionPresets: defaultModelPresets, + }, + [AMAZON_MODELS.NOVA_CANVAS]: { supportedModes: [ GENERATION_MODES.TEXT_IMAGE, GENERATION_MODES.IMAGE_VARIATION, @@ -431,7 +441,9 @@ const GenerateImagePage: React.FC = () => { const maskPromptSupported = useMemo(() => { // TODO: Remove Hard Coding return ( - imageGenModelId === TITAN_MODELS.V1 || imageGenModelId === TITAN_MODELS.V2 + imageGenModelId === AMAZON_MODELS.TITAN_V1 || + imageGenModelId === AMAZON_MODELS.TITAN_V2 || + imageGenModelId === AMAZON_MODELS.NOVA_CANVAS ); }, [imageGenModelId]);