diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md index 7f0ab70b..445efc40 100644 --- a/docs/DEVELOPMENT.md +++ b/docs/DEVELOPMENT.md @@ -43,7 +43,6 @@ export VITE_APP_SELF_SIGN_UP_ENABLED= export VITE_APP_MODEL_REGION= export VITE_APP_MODEL_IDS= export VITE_APP_IMAGE_MODEL_IDS= -export VITE_APP_MODEL_FEATURE_FLAGS= export VITE_APP_ENDPOINT_NAMES= export VITE_APP_SAMLAUTH_ENABLED= export VITE_APP_SAML_COGNITO_DOMAIN_NAME= @@ -68,7 +67,6 @@ export VITE_APP_SELF_SIGN_UP_ENABLED=true export VITE_APP_MODEL_REGION=us-west-2 export VITE_APP_MODEL_IDS=["anthropic.claude-instant-v1","anthropic.claude-v2"] export VITE_APP_IMAGE_MODEL_IDS=["stability.stable-diffusion-xl-v1","amazon.titan-image-generator-v1"] -export VITE_APP_MODEL_FEATURE_FLAGS=[...] export VITE_APP_ENDPOINT_NAMES=[] export VITE_APP_SAMLAUTH_ENABLED=true export VITE_APP_SAML_COGNITO_DOMAIN_NAME=your-preferred-name.auth.ap-northeast-1.amazoncognito.com diff --git a/package-lock.json b/package-lock.json index be48480f..e5157781 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7608,6 +7608,10 @@ "react-dom": ">=16.8.0" } }, + "node_modules/@generative-ai-use-cases-jp/common": { + "resolved": "packages/common", + "link": true + }, "node_modules/@headlessui/react": { "version": "1.7.19", "resolved": "https://registry.npmjs.org/@headlessui/react/-/react-1.7.19.tgz", @@ -21230,6 +21234,10 @@ "typescript": "~5.4.5" } }, + "packages/common": { + "name": "@generative-ai-use-cases-jp/common", + "version": "1.0.0" + }, "packages/types": { "name": "@types/generative-ai-use-cases-jp", "dependencies": { diff --git a/packages/cdk/lib/construct/api.ts b/packages/cdk/lib/construct/api.ts index 48f80ec2..e08e7a31 100644 --- a/packages/cdk/lib/construct/api.ts +++ b/packages/cdk/lib/construct/api.ts @@ -20,7 +20,8 @@ import { BucketEncryption, HttpMethods, } from 'aws-cdk-lib/aws-s3'; -import { Agent, AgentMap, FeatureFlags } from 'generative-ai-use-cases-jp'; +import { Agent, AgentMap } from 'generative-ai-use-cases-jp'; +import { modelFeatureFlags } from '@generative-ai-use-cases-jp/common'; export interface BackendApiProps { userPool: UserPool; @@ -38,7 +39,6 @@ export class Api extends Construct { readonly optimizePromptFunction: NodejsFunction; readonly modelRegion: string; readonly modelIds: string[]; - readonly modelFeatureFlags: Record; readonly imageGenerationModelIds: string[]; readonly endpointNames: string[]; readonly agentNames: string[]; @@ -70,87 +70,6 @@ export class Api extends Construct { ...(this.node.tryGetContext('agents') || []), ]; - // Manage Model Feature - // https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference-supported-models-features.html - const MODEL_FEATURE: Record = { - TEXT_ONLY: { text: true, doc: false, image: false, video: false }, - TEXT_DOC: { text: true, doc: true, image: false, video: false }, - TEXT_DOC_IMAGE: { text: true, doc: true, image: true, video: false }, - TEXT_DOC_IMAGE_VIDEO: { text: true, doc: true, image: true, video: true }, - IMAGE_GEN: { image_gen: true }, - VIDEO_GEN: { video_gen: true }, - }; - const modelFeatureFlags: Record = { - // Anthropic - 'anthropic.claude-3-5-sonnet-20241022-v2:0': MODEL_FEATURE.TEXT_DOC_IMAGE, - 'anthropic.claude-3-5-haiku-20241022-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, - 'anthropic.claude-3-5-sonnet-20240620-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, - 'anthropic.claude-3-opus-20240229-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, - 'anthropic.claude-3-sonnet-20240229-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, - 'anthropic.claude-3-haiku-20240307-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, - 'us.anthropic.claude-3-5-sonnet-20241022-v2:0': - MODEL_FEATURE.TEXT_DOC_IMAGE, - 'us.anthropic.claude-3-5-haiku-20241022-v1:0': - MODEL_FEATURE.TEXT_DOC_IMAGE, - 'us.anthropic.claude-3-5-sonnet-20240620-v1:0': - MODEL_FEATURE.TEXT_DOC_IMAGE, - 'us.anthropic.claude-3-opus-20240229-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, - 'us.anthropic.claude-3-sonnet-20240229-v1:0': - MODEL_FEATURE.TEXT_DOC_IMAGE, - 'us.anthropic.claude-3-haiku-20240307-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, - 'eu.anthropic.claude-3-5-sonnet-20240620-v1:0': - MODEL_FEATURE.TEXT_DOC_IMAGE, - 'eu.anthropic.claude-3-sonnet-20240229-v1:0': - MODEL_FEATURE.TEXT_DOC_IMAGE, - 'eu.anthropic.claude-3-haiku-20240307-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, - 'apac.anthropic.claude-3-5-sonnet-20240620-v1:0': - MODEL_FEATURE.TEXT_DOC_IMAGE, - 'apac.anthropic.claude-3-sonnet-20240229-v1:0': - MODEL_FEATURE.TEXT_DOC_IMAGE, - 'apac.anthropic.claude-3-haiku-20240307-v1:0': - MODEL_FEATURE.TEXT_DOC_IMAGE, - 'anthropic.claude-v2:1': MODEL_FEATURE.TEXT_DOC, - 'anthropic.claude-v2': MODEL_FEATURE.TEXT_DOC, - 'anthropic.claude-instant-v1': MODEL_FEATURE.TEXT_DOC, - // Amazon Titan - 'amazon.titan-text-express-v1': MODEL_FEATURE.TEXT_DOC, - 'amazon.titan-text-premier-v1:0': MODEL_FEATURE.TEXT_ONLY, - // Meta - 'meta.llama3-8b-instruct-v1:0': MODEL_FEATURE.TEXT_DOC, - 'meta.llama3-70b-instruct-v1:0': MODEL_FEATURE.TEXT_DOC, - 'meta.llama3-1-8b-instruct-v1:0': MODEL_FEATURE.TEXT_DOC, - 'meta.llama3-1-70b-instruct-v1:0': MODEL_FEATURE.TEXT_DOC, - 'meta.llama3-1-405b-instruct-v1:0': MODEL_FEATURE.TEXT_DOC, - 'us.meta.llama3-2-1b-instruct-v1:0': MODEL_FEATURE.TEXT_DOC, - 'us.meta.llama3-2-3b-instruct-v1:0': MODEL_FEATURE.TEXT_DOC, - 'us.meta.llama3-2-11b-instruct-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, - 'us.meta.llama3-2-90b-instruct-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, - // Mistral - 'mistral.mistral-7b-instruct-v0:2': MODEL_FEATURE.TEXT_DOC, - 'mistral.mixtral-8x7b-instruct-v0:1': MODEL_FEATURE.TEXT_DOC, - 'mistral.mistral-small-2402-v1:0': MODEL_FEATURE.TEXT_ONLY, - 'mistral.mistral-large-2402-v1:0': MODEL_FEATURE.TEXT_DOC, - 'mistral.mistral-large-2407-v1:0': MODEL_FEATURE.TEXT_DOC, - // Cohere - 'cohere.command-r-v1:0': MODEL_FEATURE.TEXT_DOC, - 'cohere.command-r-plus-v1:0': MODEL_FEATURE.TEXT_DOC, - // Amazon Nova - 'amazon.nova-pro-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE_VIDEO, - 'amazon.nova-lite-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE_VIDEO, - 'amazon.nova-micro-v1:0': MODEL_FEATURE.TEXT_ONLY, - 'us.amazon.nova-pro-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE_VIDEO, - 'us.amazon.nova-lite-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE_VIDEO, - 'us.amazon.nova-micro-v1:0': MODEL_FEATURE.TEXT_ONLY, - // Stability AI Image Gen - 'stability.stable-diffusion-xl-v1': MODEL_FEATURE.IMAGE_GEN, - 'stability.sd3-large-v1:0': MODEL_FEATURE.IMAGE_GEN, - 'stability.stable-image-core-v1:0': MODEL_FEATURE.IMAGE_GEN, - 'stability.stable-image-ultra-v1:0': MODEL_FEATURE.IMAGE_GEN, - // Amazon Image Gen - 'amazon.titan-image-generator-v2:0': MODEL_FEATURE.IMAGE_GEN, - 'amazon.titan-image-generator-v1': MODEL_FEATURE.IMAGE_GEN, - }; - // Validate Model Names const supportedModelIds = Object.keys(modelFeatureFlags); for (const modelId of modelIds) { @@ -833,7 +752,6 @@ export class Api extends Construct { this.modelRegion = modelRegion; this.modelIds = modelIds; this.imageGenerationModelIds = imageGenerationModelIds; - this.modelFeatureFlags = modelFeatureFlags; this.endpointNames = endpointNames; this.agentNames = Object.keys(agentMap); this.fileBucket = fileBucket; diff --git a/packages/cdk/lib/construct/web.ts b/packages/cdk/lib/construct/web.ts index 8944d5b7..bb6a5101 100644 --- a/packages/cdk/lib/construct/web.ts +++ b/packages/cdk/lib/construct/web.ts @@ -10,7 +10,7 @@ import * as s3 from 'aws-cdk-lib/aws-s3'; import { ARecord, HostedZone, RecordTarget } from 'aws-cdk-lib/aws-route53'; import { CloudFrontTarget } from 'aws-cdk-lib/aws-route53-targets'; import { ICertificate } from 'aws-cdk-lib/aws-certificatemanager'; -import { FeatureFlags, PromptFlow } from 'generative-ai-use-cases-jp'; +import { PromptFlow } from 'generative-ai-use-cases-jp'; export interface WebProps { apiEndpointUrl: string; @@ -28,7 +28,6 @@ export interface WebProps { webAclId?: string; modelRegion: string; modelIds: string[]; - modelFeatureFlags: Record; imageGenerationModelIds: string[]; endpointNames: string[]; samlAuthEnabled: boolean; @@ -179,7 +178,6 @@ export class Web extends Construct { VITE_APP_MODEL_REGION: props.modelRegion, VITE_APP_MODEL_IDS: JSON.stringify(props.modelIds), VITE_APP_IMAGE_MODEL_IDS: JSON.stringify(props.imageGenerationModelIds), - VITE_APP_MODEL_FEATURE_FLAGS: JSON.stringify(props.modelFeatureFlags), VITE_APP_ENDPOINT_NAMES: JSON.stringify(props.endpointNames), VITE_APP_SAMLAUTH_ENABLED: props.samlAuthEnabled.toString(), VITE_APP_SAML_COGNITO_DOMAIN_NAME: diff --git a/packages/cdk/lib/generative-ai-use-cases-stack.ts b/packages/cdk/lib/generative-ai-use-cases-stack.ts index fd1024ce..c36e9e13 100644 --- a/packages/cdk/lib/generative-ai-use-cases-stack.ts +++ b/packages/cdk/lib/generative-ai-use-cases-stack.ts @@ -158,7 +158,6 @@ export class GenerativeAiUseCasesStack extends Stack { webAclId: props.webAclId, modelRegion: api.modelRegion, modelIds: api.modelIds, - modelFeatureFlags: api.modelFeatureFlags, imageGenerationModelIds: api.imageGenerationModelIds, endpointNames: api.endpointNames, samlAuthEnabled, @@ -281,10 +280,6 @@ export class GenerativeAiUseCasesStack extends Stack { value: JSON.stringify(api.imageGenerationModelIds), }); - new CfnOutput(this, 'ModelFeatureFlags', { - value: JSON.stringify(api.modelFeatureFlags), - }); - new CfnOutput(this, 'EndpointNames', { value: JSON.stringify(api.endpointNames), }); diff --git a/packages/cdk/tsconfig.json b/packages/cdk/tsconfig.json index be82b593..ea143d04 100644 --- a/packages/cdk/tsconfig.json +++ b/packages/cdk/tsconfig.json @@ -21,7 +21,7 @@ "experimentalDecorators": true, "strictPropertyInitialization": false, "typeRoots": [ - "./node_modules/@types" + "../../node_modules/@types" ], "types": [ "node" diff --git a/packages/common/package.json b/packages/common/package.json new file mode 100644 index 00000000..b388ac5c --- /dev/null +++ b/packages/common/package.json @@ -0,0 +1,6 @@ +{ + "name": "@generative-ai-use-cases-jp/common", + "version": "1.0.0", + "private": true, + "main": "src/index.ts" +} \ No newline at end of file diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts new file mode 100644 index 00000000..9f8ccadd --- /dev/null +++ b/packages/common/src/index.ts @@ -0,0 +1 @@ +export * from './model'; diff --git a/packages/common/src/model.ts b/packages/common/src/model.ts new file mode 100644 index 00000000..e2e5a698 --- /dev/null +++ b/packages/common/src/model.ts @@ -0,0 +1,74 @@ +import { FeatureFlags } from 'generative-ai-use-cases-jp'; + +// Manage Model Feature +// https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference-supported-models-features.html +const MODEL_FEATURE: Record = { + TEXT_ONLY: { text: true, doc: false, image: false, video: false }, + TEXT_DOC: { text: true, doc: true, image: false, video: false }, + TEXT_DOC_IMAGE: { text: true, doc: true, image: true, video: false }, + TEXT_DOC_IMAGE_VIDEO: { text: true, doc: true, image: true, video: true }, + IMAGE_GEN: { image_gen: true }, + VIDEO_GEN: { video_gen: true }, +}; +export const modelFeatureFlags: Record = { + // Anthropic + 'anthropic.claude-3-5-sonnet-20241022-v2:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + 'anthropic.claude-3-5-haiku-20241022-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + 'anthropic.claude-3-5-sonnet-20240620-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + 'anthropic.claude-3-opus-20240229-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + 'anthropic.claude-3-sonnet-20240229-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + 'anthropic.claude-3-haiku-20240307-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + 'us.anthropic.claude-3-5-sonnet-20241022-v2:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + 'us.anthropic.claude-3-5-haiku-20241022-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + 'us.anthropic.claude-3-5-sonnet-20240620-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + 'us.anthropic.claude-3-opus-20240229-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + 'us.anthropic.claude-3-sonnet-20240229-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + 'us.anthropic.claude-3-haiku-20240307-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + 'eu.anthropic.claude-3-5-sonnet-20240620-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + 'eu.anthropic.claude-3-sonnet-20240229-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + 'eu.anthropic.claude-3-haiku-20240307-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + 'apac.anthropic.claude-3-5-sonnet-20240620-v1:0': + MODEL_FEATURE.TEXT_DOC_IMAGE, + 'apac.anthropic.claude-3-sonnet-20240229-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + 'apac.anthropic.claude-3-haiku-20240307-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + 'anthropic.claude-v2:1': MODEL_FEATURE.TEXT_DOC, + 'anthropic.claude-v2': MODEL_FEATURE.TEXT_DOC, + 'anthropic.claude-instant-v1': MODEL_FEATURE.TEXT_DOC, + // Amazon Titan + 'amazon.titan-text-express-v1': MODEL_FEATURE.TEXT_DOC, + 'amazon.titan-text-premier-v1:0': MODEL_FEATURE.TEXT_ONLY, + // Meta + 'meta.llama3-8b-instruct-v1:0': MODEL_FEATURE.TEXT_DOC, + 'meta.llama3-70b-instruct-v1:0': MODEL_FEATURE.TEXT_DOC, + 'meta.llama3-1-8b-instruct-v1:0': MODEL_FEATURE.TEXT_DOC, + 'meta.llama3-1-70b-instruct-v1:0': MODEL_FEATURE.TEXT_DOC, + 'meta.llama3-1-405b-instruct-v1:0': MODEL_FEATURE.TEXT_DOC, + 'us.meta.llama3-2-1b-instruct-v1:0': MODEL_FEATURE.TEXT_DOC, + 'us.meta.llama3-2-3b-instruct-v1:0': MODEL_FEATURE.TEXT_DOC, + 'us.meta.llama3-2-11b-instruct-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + 'us.meta.llama3-2-90b-instruct-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE, + // Mistral + 'mistral.mistral-7b-instruct-v0:2': MODEL_FEATURE.TEXT_DOC, + 'mistral.mixtral-8x7b-instruct-v0:1': MODEL_FEATURE.TEXT_DOC, + 'mistral.mistral-small-2402-v1:0': MODEL_FEATURE.TEXT_ONLY, + 'mistral.mistral-large-2402-v1:0': MODEL_FEATURE.TEXT_DOC, + 'mistral.mistral-large-2407-v1:0': MODEL_FEATURE.TEXT_DOC, + // Cohere + 'cohere.command-r-v1:0': MODEL_FEATURE.TEXT_DOC, + 'cohere.command-r-plus-v1:0': MODEL_FEATURE.TEXT_DOC, + // Amazon Nova + 'amazon.nova-pro-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE_VIDEO, + 'amazon.nova-lite-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE_VIDEO, + 'amazon.nova-micro-v1:0': MODEL_FEATURE.TEXT_ONLY, + 'us.amazon.nova-pro-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE_VIDEO, + 'us.amazon.nova-lite-v1:0': MODEL_FEATURE.TEXT_DOC_IMAGE_VIDEO, + 'us.amazon.nova-micro-v1:0': MODEL_FEATURE.TEXT_ONLY, + // Stability AI Image Gen + 'stability.stable-diffusion-xl-v1': MODEL_FEATURE.IMAGE_GEN, + 'stability.sd3-large-v1:0': MODEL_FEATURE.IMAGE_GEN, + 'stability.stable-image-core-v1:0': MODEL_FEATURE.IMAGE_GEN, + 'stability.stable-image-ultra-v1:0': MODEL_FEATURE.IMAGE_GEN, + // Amazon Image Gen + 'amazon.titan-image-generator-v2:0': MODEL_FEATURE.IMAGE_GEN, + 'amazon.titan-image-generator-v1': MODEL_FEATURE.IMAGE_GEN, +}; diff --git a/packages/common/tsconfig.json b/packages/common/tsconfig.json new file mode 100644 index 00000000..ccd5c10e --- /dev/null +++ b/packages/common/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "rootDir": "src", + "composite": true, + "declaration": true, + "declarationMap": true, + "esModuleInterop": true, + "skipLibCheck": true + }, + "include": ["src"], + "exclude": ["node_modules", "dist"] +} \ No newline at end of file diff --git a/packages/web/src/hooks/useModel.ts b/packages/web/src/hooks/useModel.ts index 2b1ae5ff..ab244d89 100644 --- a/packages/web/src/hooks/useModel.ts +++ b/packages/web/src/hooks/useModel.ts @@ -1,4 +1,5 @@ -import { FeatureFlags, Model } from 'generative-ai-use-cases-jp'; +import { Model } from 'generative-ai-use-cases-jp'; +import { modelFeatureFlags } from '@generative-ai-use-cases-jp/common'; const modelRegion = import.meta.env.VITE_APP_MODEL_REGION; @@ -6,9 +7,6 @@ const modelRegion = import.meta.env.VITE_APP_MODEL_REGION; const bedrockModelIds: string[] = JSON.parse(import.meta.env.VITE_APP_MODEL_IDS) .map((name: string) => name.trim()) .filter((name: string) => name); -const modelFeatureFlags: Record = JSON.parse( - import.meta.env.VITE_APP_MODEL_FEATURE_FLAGS -); const visionModelIds: string[] = bedrockModelIds.filter( (modelId) => modelFeatureFlags[modelId].image ); diff --git a/packages/web/src/vite-env.d.ts b/packages/web/src/vite-env.d.ts index eb74d3c3..fa4e85f9 100644 --- a/packages/web/src/vite-env.d.ts +++ b/packages/web/src/vite-env.d.ts @@ -17,7 +17,6 @@ interface ImportMetaEnv { readonly VITE_APP_MODEL_REGION: string; readonly VITE_APP_MODEL_IDS: string; readonly VITE_APP_IMAGE_MODEL_IDS: string; - readonly VITE_APP_MODEL_FEATURE_FLAGS: string; readonly VITE_APP_ENDPOINT_NAMES: string; readonly VITE_APP_SAMLAUTH_ENABLED: string; readonly VITE_APP_SAML_COGNITO_DOMAIN_NAME: string; diff --git a/setup-env.sh b/setup-env.sh index 24b43ca0..ac82ad7f 100644 --- a/setup-env.sh +++ b/setup-env.sh @@ -25,7 +25,6 @@ export VITE_APP_SELF_SIGN_UP_ENABLED=`extract_value "$stack_output" SelfSignUpEn export VITE_APP_MODEL_REGION=`extract_value "$stack_output" ModelRegion` export VITE_APP_MODEL_IDS=`extract_value "$stack_output" ModelIds` export VITE_APP_IMAGE_MODEL_IDS=`extract_value "$stack_output" ImageGenerateModelIds` -export VITE_APP_MODEL_FEATURE_FLAGS=`extract_value "$stack_output" ModelFeatureFlags` export VITE_APP_ENDPOINT_NAMES=`extract_value "$stack_output" EndpointNames` export VITE_APP_SAMLAUTH_ENABLED=`extract_value "$stack_output" SamlAuthEnabled` export VITE_APP_SAML_COGNITO_DOMAIN_NAME=`extract_value "$stack_output" SamlCognitoDomainName`