diff --git a/README.md b/README.md index 2aaa80b4..0df4cca8 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,6 @@ npm run cdk:deploy - [コスト関連設定](/docs/DEPLOY_OPTION.md#コスト関連設定) - [Kendraのインデックスを自動で作成・削除するスケジュールを設定する](/docs/DEPLOY_OPTION.md#Kendraを自動でオン・オフするスケジュールを設定する) - [モニタリング用のダッシュボードの有効化](/docs/DEPLOY_OPTION.md#モニタリング用のダッシュボードの有効化) -- [ファイルアップロード機能の有効化](/docs/DEPLOY_OPTION.md#ファイルアップロード機能の有効化) - [別 AWS アカウントの Bedrock を利用したい場合](/docs/DEPLOY_OPTION.md#別-AWS-アカウントの-Bedrock-を利用したい場合) ## その他 diff --git a/docs/DEPLOY_OPTION.md b/docs/DEPLOY_OPTION.md index ab2c3df1..b32df4b7 100644 --- a/docs/DEPLOY_OPTION.md +++ b/docs/DEPLOY_OPTION.md @@ -362,6 +362,7 @@ PromptFlow チャットユースケースでは、作成済みの Prompt Flow 2024/06 現在、マルチモーダルのモデルは以下です。 ``` +"anthropic.claude-3-5-sonnet-20241022-v2:0", "anthropic.claude-3-5-sonnet-20240620-v1:0", "anthropic.claude-3-opus-20240229-v1:0", "anthropic.claude-3-sonnet-20240229-v1:0", @@ -382,6 +383,7 @@ PromptFlow チャットユースケースでは、作成済みの Prompt Flow ```json "modelIds": [ + "anthropic.claude-3-5-sonnet-20241022-v2:0", "anthropic.claude-3-5-sonnet-20240620-v1:0", "anthropic.claude-3-opus-20240229-v1:0", "anthropic.claude-3-sonnet-20240229-v1:0", @@ -409,6 +411,7 @@ PromptFlow チャットユースケースでは、作成済みの Prompt Flow このソリューションが対応しているテキスト生成モデルは以下です。 ``` +"anthropic.claude-3-5-sonnet-20241022-v2:0", "anthropic.claude-3-5-sonnet-20240620-v1:0", "anthropic.claude-3-opus-20240229-v1:0", "anthropic.claude-3-sonnet-20240229-v1:0", @@ -450,7 +453,10 @@ PromptFlow チャットユースケースでは、作成済みの Prompt Flow ``` "amazon.titan-image-generator-v2:0", "amazon.titan-image-generator-v1", -"stability.stable-diffusion-xl-v1" +"stability.stable-diffusion-xl-v1", +"stability.sd3-large-v1:0", +"stability.stable-image-core-v1:0", +"stability.stable-image-ultra-v1:0" ``` **指定したリージョンで指定したモデルが有効化されているかご確認ください。** @@ -482,6 +488,7 @@ PromptFlow チャットユースケースでは、作成済みの Prompt Flow ```bash "modelRegion": "us-west-2", "modelIds": [ + "anthropic.claude-3-5-sonnet-20241022-v2:0", "anthropic.claude-3-5-sonnet-20240620-v1:0", "anthropic.claude-3-opus-20240229-v1:0", "anthropic.claude-3-sonnet-20240229-v1:0", @@ -495,7 +502,10 @@ PromptFlow チャットユースケースでは、作成済みの Prompt Flow "imageGenerationModelIds": [ "amazon.titan-image-generator-v2:0", "amazon.titan-image-generator-v1", - "stability.stable-diffusion-xl-v1" + "stability.stable-diffusion-xl-v1", + "stability.sd3-large-v1:0", + "stability.stable-image-core-v1:0", + "stability.stable-image-ultra-v1:0" ], ``` ### cross-region inference が対応しているモデルで us(北部バージニアもしくはオレゴン) の Amazon Bedrock のモデルを利用する場合 @@ -517,7 +527,10 @@ PromptFlow チャットユースケースでは、作成済みの Prompt Flow "imageGenerationModelIds": [ "amazon.titan-image-generator-v2:0", "amazon.titan-image-generator-v1", - "stability.stable-diffusion-xl-v1" + "stability.stable-diffusion-xl-v1", + "stability.sd3-large-v1:0", + "stability.stable-image-core-v1:0", + "stability.stable-image-ultra-v1:0" ], ``` @@ -774,34 +787,6 @@ context の `dashboard` に `true` を設定します。(デフォルトは `fal > [!NOTE] > モニタリング用のダッシュボードを有効後に、再度無効化する場合は、`dashboard: false` にして再デプロイすればモニタリング用ダッシュボードは無効化されますが、`GenerativeAiUseCasesDashboardStack` 自体は残ります。マネージメントコンソールを開き、modelRegion の CloudFormation から `GenerativeAiUseCasesDashboardStack` というスタックを削除することで完全に消去ができます。 -## ファイルアップロード機能の有効化 - -PDF や Excel などのファイルをアップロードしてテキストを抽出する、ファイルアップロード機能を利用することができます。対応しているファイルは、csv, doc, docx, md, pdf, ppt, pptx, tsv, xlsx です。 - -**[packages/cdk/cdk.json](/packages/cdk/cdk.json) を編集** -```json -{ - "context": { - "recognizeFileEnabled": true, - "vpcId": null - } -} -``` - -ファイルアップロード機能は ECS (Fargate) 上で実行されます。`vpcId`を指定しない場合は、VPC が新たに作成されます。また、Fargate 上で動くコンテナのビルドを行うために、デプロイ用のマシンでは Docker がインストールされている必要があり、Docker デーモンが起動している必要があります。 - -既存の VPC を使用する場合は、`vpcId` を指定してください。 - - -```json -{ - "context": { - "recognizeFileEnabled": true, - "vpcId": "vpc-xxxxxxxxxxxxxxxxx" - } -} -``` - ## カスタムドメインの使用 Web サイトの URL としてカスタムドメインを使用することができます。同一 AWS アカウントの Route53 にパブリックホストゾーンが作成済みであることが必要です。パブリックホストゾーンについてはこちらをご参照ください: [パブリックホストゾーンの使用 - Amazon Route 53](https://docs.aws.amazon.com/ja_jp/Route53/latest/DeveloperGuide/AboutHZWorkingWith.html) diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md index 0d9e57c0..a481d9d5 100644 --- a/docs/DEVELOPMENT.md +++ b/docs/DEVELOPMENT.md @@ -49,7 +49,6 @@ export VITE_APP_SAMLAUTH_ENABLED= export VITE_APP_SAML_COGNITO_DOMAIN_NAME= export VITE_APP_SAML_COGNITO_FEDERATED_IDENTITY_PROVIDER_NAME= export VITE_APP_AGENT_NAMES= -export VITE_APP_RECOGNIZE_FILE_ENABLED=<ファイルアップロード Flag> ``` 具体例は以下です。 @@ -73,7 +72,6 @@ export VITE_APP_SAMLAUTH_ENABLED=true export VITE_APP_SAML_COGNITO_DOMAIN_NAME=your-preferred-name.auth.ap-northeast-1.amazoncognito.com export VITE_APP_SAML_COGNITO_FEDERATED_IDENTITY_PROVIDER_NAME=EntraID export VITE_APP_AGENT_NAMES=["SearchEngine"] -export VITE_APP_RECOGNIZE_FILE_ENABLED=true ``` #### `.env` ファイルを利用する方法 diff --git a/imgs/arch.drawio.png b/imgs/arch.drawio.png index 03d7f84b..545b1c99 100644 Binary files a/imgs/arch.drawio.png and b/imgs/arch.drawio.png differ diff --git a/package-lock.json b/package-lock.json index 98904ed5..7e36723a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -595,6 +595,59 @@ "tslib": "^2.6.2" } }, + "node_modules/@aws-sdk/client-bedrock-agent": { + "version": "3.668.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/client-bedrock-agent/-/client-bedrock-agent-3.668.0.tgz", + "integrity": "sha512-MJY/o9OM6pHHrl8zTSW2xG03JAqm1OUFu6JNI6vbxXix3o/YUKvpZdvQ1bYpaPFqgfRf3PtVoH8zvLL9c5BRHw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/sha256-browser": "5.2.0", + "@aws-crypto/sha256-js": "5.2.0", + "@aws-sdk/client-sso-oidc": "3.668.0", + "@aws-sdk/client-sts": "3.668.0", + "@aws-sdk/core": "3.667.0", + "@aws-sdk/credential-provider-node": "3.668.0", + "@aws-sdk/middleware-host-header": "3.667.0", + "@aws-sdk/middleware-logger": "3.667.0", + "@aws-sdk/middleware-recursion-detection": "3.667.0", + "@aws-sdk/middleware-user-agent": "3.668.0", + "@aws-sdk/region-config-resolver": "3.667.0", + "@aws-sdk/types": "3.667.0", + "@aws-sdk/util-endpoints": "3.667.0", + "@aws-sdk/util-user-agent-browser": "3.667.0", + "@aws-sdk/util-user-agent-node": "3.668.0", + "@smithy/config-resolver": "^3.0.9", + "@smithy/core": "^2.4.8", + "@smithy/fetch-http-handler": "^3.2.9", + "@smithy/hash-node": "^3.0.7", + "@smithy/invalid-dependency": "^3.0.7", + "@smithy/middleware-content-length": "^3.0.9", + "@smithy/middleware-endpoint": "^3.1.4", + "@smithy/middleware-retry": "^3.0.23", + "@smithy/middleware-serde": "^3.0.7", + "@smithy/middleware-stack": "^3.0.7", + "@smithy/node-config-provider": "^3.1.8", + "@smithy/node-http-handler": "^3.2.4", + "@smithy/protocol-http": "^4.1.4", + "@smithy/smithy-client": "^3.4.0", + "@smithy/types": "^3.5.0", + "@smithy/url-parser": "^3.0.7", + "@smithy/util-base64": "^3.0.0", + "@smithy/util-body-length-browser": "^3.0.0", + "@smithy/util-body-length-node": "^3.0.0", + "@smithy/util-defaults-mode-browser": "^3.0.23", + "@smithy/util-defaults-mode-node": "^3.0.23", + "@smithy/util-endpoints": "^2.1.3", + "@smithy/util-middleware": "^3.0.7", + "@smithy/util-retry": "^3.0.7", + "@smithy/util-utf8": "^3.0.0", + "tslib": "^2.6.2", + "uuid": "^9.0.1" + }, + "engines": { + "node": ">=16.0.0" + } + }, "node_modules/@aws-sdk/client-bedrock-agent-runtime": { "version": "3.665.0", "resolved": "https://registry.npmjs.org/@aws-sdk/client-bedrock-agent-runtime/-/client-bedrock-agent-runtime-3.665.0.tgz", @@ -676,6 +729,497 @@ "node": ">=16.0.0" } }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/client-sso": { + "version": "3.668.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/client-sso/-/client-sso-3.668.0.tgz", + "integrity": "sha512-21YehzNmlaVbB6f4gAg9CTl6djExE7yxuWaRgbFugCtFhqZbmNhrh826B6cGvPVc5Dxx2rdMdI/SxTujtTJvag==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/sha256-browser": "5.2.0", + "@aws-crypto/sha256-js": "5.2.0", + "@aws-sdk/core": "3.667.0", + "@aws-sdk/middleware-host-header": "3.667.0", + "@aws-sdk/middleware-logger": "3.667.0", + "@aws-sdk/middleware-recursion-detection": "3.667.0", + "@aws-sdk/middleware-user-agent": "3.668.0", + "@aws-sdk/region-config-resolver": "3.667.0", + "@aws-sdk/types": "3.667.0", + "@aws-sdk/util-endpoints": "3.667.0", + "@aws-sdk/util-user-agent-browser": "3.667.0", + "@aws-sdk/util-user-agent-node": "3.668.0", + "@smithy/config-resolver": "^3.0.9", + "@smithy/core": "^2.4.8", + "@smithy/fetch-http-handler": "^3.2.9", + "@smithy/hash-node": "^3.0.7", + "@smithy/invalid-dependency": "^3.0.7", + "@smithy/middleware-content-length": "^3.0.9", + "@smithy/middleware-endpoint": "^3.1.4", + "@smithy/middleware-retry": "^3.0.23", + "@smithy/middleware-serde": "^3.0.7", + "@smithy/middleware-stack": "^3.0.7", + "@smithy/node-config-provider": "^3.1.8", + "@smithy/node-http-handler": "^3.2.4", + "@smithy/protocol-http": "^4.1.4", + "@smithy/smithy-client": "^3.4.0", + "@smithy/types": "^3.5.0", + "@smithy/url-parser": "^3.0.7", + "@smithy/util-base64": "^3.0.0", + "@smithy/util-body-length-browser": "^3.0.0", + "@smithy/util-body-length-node": "^3.0.0", + "@smithy/util-defaults-mode-browser": "^3.0.23", + "@smithy/util-defaults-mode-node": "^3.0.23", + "@smithy/util-endpoints": "^2.1.3", + "@smithy/util-middleware": "^3.0.7", + "@smithy/util-retry": "^3.0.7", + "@smithy/util-utf8": "^3.0.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/client-sso-oidc": { + "version": "3.668.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/client-sso-oidc/-/client-sso-oidc-3.668.0.tgz", + "integrity": "sha512-b1Ib/92tcjOPXWYILfNuOOd2CYxmlr9lUfoZZBy/uwZCMObI6gtcpdUjfefyJohWfR+rk1WtsXi/sIXKxAhl/g==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/sha256-browser": "5.2.0", + "@aws-crypto/sha256-js": "5.2.0", + "@aws-sdk/core": "3.667.0", + "@aws-sdk/credential-provider-node": "3.668.0", + "@aws-sdk/middleware-host-header": "3.667.0", + "@aws-sdk/middleware-logger": "3.667.0", + "@aws-sdk/middleware-recursion-detection": "3.667.0", + "@aws-sdk/middleware-user-agent": "3.668.0", + "@aws-sdk/region-config-resolver": "3.667.0", + "@aws-sdk/types": "3.667.0", + "@aws-sdk/util-endpoints": "3.667.0", + "@aws-sdk/util-user-agent-browser": "3.667.0", + "@aws-sdk/util-user-agent-node": "3.668.0", + "@smithy/config-resolver": "^3.0.9", + "@smithy/core": "^2.4.8", + "@smithy/fetch-http-handler": "^3.2.9", + "@smithy/hash-node": "^3.0.7", + "@smithy/invalid-dependency": "^3.0.7", + "@smithy/middleware-content-length": "^3.0.9", + "@smithy/middleware-endpoint": "^3.1.4", + "@smithy/middleware-retry": "^3.0.23", + "@smithy/middleware-serde": "^3.0.7", + "@smithy/middleware-stack": "^3.0.7", + "@smithy/node-config-provider": "^3.1.8", + "@smithy/node-http-handler": "^3.2.4", + "@smithy/protocol-http": "^4.1.4", + "@smithy/smithy-client": "^3.4.0", + "@smithy/types": "^3.5.0", + "@smithy/url-parser": "^3.0.7", + "@smithy/util-base64": "^3.0.0", + "@smithy/util-body-length-browser": "^3.0.0", + "@smithy/util-body-length-node": "^3.0.0", + "@smithy/util-defaults-mode-browser": "^3.0.23", + "@smithy/util-defaults-mode-node": "^3.0.23", + "@smithy/util-endpoints": "^2.1.3", + "@smithy/util-middleware": "^3.0.7", + "@smithy/util-retry": "^3.0.7", + "@smithy/util-utf8": "^3.0.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + }, + "peerDependencies": { + "@aws-sdk/client-sts": "^3.668.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/client-sts": { + "version": "3.668.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/client-sts/-/client-sts-3.668.0.tgz", + "integrity": "sha512-Ele3N6WveoMsF2mZpN/1tM0jsu7qOUXWX7RKV1U4Dhe0TMbW1KdVIXz1oirWlc0BxCels7HX+CS1N7gg1axhwg==", + "license": "Apache-2.0", + "dependencies": { + "@aws-crypto/sha256-browser": "5.2.0", + "@aws-crypto/sha256-js": "5.2.0", + "@aws-sdk/client-sso-oidc": "3.668.0", + "@aws-sdk/core": "3.667.0", + "@aws-sdk/credential-provider-node": "3.668.0", + "@aws-sdk/middleware-host-header": "3.667.0", + "@aws-sdk/middleware-logger": "3.667.0", + "@aws-sdk/middleware-recursion-detection": "3.667.0", + "@aws-sdk/middleware-user-agent": "3.668.0", + "@aws-sdk/region-config-resolver": "3.667.0", + "@aws-sdk/types": "3.667.0", + "@aws-sdk/util-endpoints": "3.667.0", + "@aws-sdk/util-user-agent-browser": "3.667.0", + "@aws-sdk/util-user-agent-node": "3.668.0", + "@smithy/config-resolver": "^3.0.9", + "@smithy/core": "^2.4.8", + "@smithy/fetch-http-handler": "^3.2.9", + "@smithy/hash-node": "^3.0.7", + "@smithy/invalid-dependency": "^3.0.7", + "@smithy/middleware-content-length": "^3.0.9", + "@smithy/middleware-endpoint": "^3.1.4", + "@smithy/middleware-retry": "^3.0.23", + "@smithy/middleware-serde": "^3.0.7", + "@smithy/middleware-stack": "^3.0.7", + "@smithy/node-config-provider": "^3.1.8", + "@smithy/node-http-handler": "^3.2.4", + "@smithy/protocol-http": "^4.1.4", + "@smithy/smithy-client": "^3.4.0", + "@smithy/types": "^3.5.0", + "@smithy/url-parser": "^3.0.7", + "@smithy/util-base64": "^3.0.0", + "@smithy/util-body-length-browser": "^3.0.0", + "@smithy/util-body-length-node": "^3.0.0", + "@smithy/util-defaults-mode-browser": "^3.0.23", + "@smithy/util-defaults-mode-node": "^3.0.23", + "@smithy/util-endpoints": "^2.1.3", + "@smithy/util-middleware": "^3.0.7", + "@smithy/util-retry": "^3.0.7", + "@smithy/util-utf8": "^3.0.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/core": { + "version": "3.667.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/core/-/core-3.667.0.tgz", + "integrity": "sha512-pMcDVI7Tmdsc8R3sDv0Omj/4iRParGY+uJtAfF669WnZfDfaBQaix2Mq7+Mu08vdjqO9K3gicFvjk9S1VLmOKA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "3.667.0", + "@smithy/core": "^2.4.8", + "@smithy/node-config-provider": "^3.1.8", + "@smithy/property-provider": "^3.1.7", + "@smithy/protocol-http": "^4.1.4", + "@smithy/signature-v4": "^4.2.0", + "@smithy/smithy-client": "^3.4.0", + "@smithy/types": "^3.5.0", + "@smithy/util-middleware": "^3.0.7", + "fast-xml-parser": "4.4.1", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/credential-provider-env": { + "version": "3.667.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-env/-/credential-provider-env-3.667.0.tgz", + "integrity": "sha512-zZbrkkaPc54WXm+QAnpuv0LPNfsts0HPPd+oCECGs7IQRaFsGj187cwvPg9RMWDFZqpm64MdBDoA8OQHsqzYCw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "3.667.0", + "@aws-sdk/types": "3.667.0", + "@smithy/property-provider": "^3.1.7", + "@smithy/types": "^3.5.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/credential-provider-http": { + "version": "3.667.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-http/-/credential-provider-http-3.667.0.tgz", + "integrity": "sha512-sjtybFfERZWiqTY7fswBxKQLvUkiCucOWyqh3IaPo/4nE1PXRnaZCVG0+kRBPrYIxWqiVwytvZzMJy8sVZcG0A==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "3.667.0", + "@aws-sdk/types": "3.667.0", + "@smithy/fetch-http-handler": "^3.2.9", + "@smithy/node-http-handler": "^3.2.4", + "@smithy/property-provider": "^3.1.7", + "@smithy/protocol-http": "^4.1.4", + "@smithy/smithy-client": "^3.4.0", + "@smithy/types": "^3.5.0", + "@smithy/util-stream": "^3.1.9", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/credential-provider-ini": { + "version": "3.668.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-ini/-/credential-provider-ini-3.668.0.tgz", + "integrity": "sha512-npu7qBM8Qu+BzRh+omBvcnA9Hxt/5HZ6ifACtLUqqkPLhCgINSpVruVqDXJHinl6DrcmTL12XM+60VW90fq2uA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "3.667.0", + "@aws-sdk/credential-provider-env": "3.667.0", + "@aws-sdk/credential-provider-http": "3.667.0", + "@aws-sdk/credential-provider-process": "3.667.0", + "@aws-sdk/credential-provider-sso": "3.668.0", + "@aws-sdk/credential-provider-web-identity": "3.667.0", + "@aws-sdk/types": "3.667.0", + "@smithy/credential-provider-imds": "^3.2.4", + "@smithy/property-provider": "^3.1.7", + "@smithy/shared-ini-file-loader": "^3.1.8", + "@smithy/types": "^3.5.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + }, + "peerDependencies": { + "@aws-sdk/client-sts": "^3.668.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/credential-provider-node": { + "version": "3.668.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-node/-/credential-provider-node-3.668.0.tgz", + "integrity": "sha512-QHD6Y6xurKsHGQ7U2Az0UHu3R31mq7uokuMrWU9IIWB4Qa5t/Pkt4Od8TYXL/V4uAOthsLdchgfeCFSleOZMEA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/credential-provider-env": "3.667.0", + "@aws-sdk/credential-provider-http": "3.667.0", + "@aws-sdk/credential-provider-ini": "3.668.0", + "@aws-sdk/credential-provider-process": "3.667.0", + "@aws-sdk/credential-provider-sso": "3.668.0", + "@aws-sdk/credential-provider-web-identity": "3.667.0", + "@aws-sdk/types": "3.667.0", + "@smithy/credential-provider-imds": "^3.2.4", + "@smithy/property-provider": "^3.1.7", + "@smithy/shared-ini-file-loader": "^3.1.8", + "@smithy/types": "^3.5.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/credential-provider-process": { + "version": "3.667.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-process/-/credential-provider-process-3.667.0.tgz", + "integrity": "sha512-HZHnvop32fKgsNHkdhVaul7UzQ25sEc0j9yqA4bjhtbk0ECl42kj3f1pJ+ZU/YD9ut8lMJs/vVqiOdNThVdeBw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "3.667.0", + "@aws-sdk/types": "3.667.0", + "@smithy/property-provider": "^3.1.7", + "@smithy/shared-ini-file-loader": "^3.1.8", + "@smithy/types": "^3.5.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/credential-provider-sso": { + "version": "3.668.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-sso/-/credential-provider-sso-3.668.0.tgz", + "integrity": "sha512-cO14tsL7Lmyq4HfRHBBjEmcBDhlXv4eVgY8DQ9e/ujPFU+b99xiZiV80JSkJ8Kz99+woFl6pFo9PYp36YaI+Pw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/client-sso": "3.668.0", + "@aws-sdk/core": "3.667.0", + "@aws-sdk/token-providers": "3.667.0", + "@aws-sdk/types": "3.667.0", + "@smithy/property-provider": "^3.1.7", + "@smithy/shared-ini-file-loader": "^3.1.8", + "@smithy/types": "^3.5.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/credential-provider-web-identity": { + "version": "3.667.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-web-identity/-/credential-provider-web-identity-3.667.0.tgz", + "integrity": "sha512-t8CFlZMD/1p/8Cli3rvRiTJpjr/8BO64gw166AHgFZYSN2h95L2l1tcW0jpsc3PprA32nLg1iQVKYt4WGM4ugw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "3.667.0", + "@aws-sdk/types": "3.667.0", + "@smithy/property-provider": "^3.1.7", + "@smithy/types": "^3.5.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + }, + "peerDependencies": { + "@aws-sdk/client-sts": "^3.667.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/middleware-host-header": { + "version": "3.667.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-host-header/-/middleware-host-header-3.667.0.tgz", + "integrity": "sha512-Z7fIAMQnPegs7JjAQvlOeWXwpMRfegh5eCoIP6VLJIeR6DLfYKbP35JBtt98R6DXslrN2RsbTogjbxPEDQfw1w==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "3.667.0", + "@smithy/protocol-http": "^4.1.4", + "@smithy/types": "^3.5.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/middleware-logger": { + "version": "3.667.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-logger/-/middleware-logger-3.667.0.tgz", + "integrity": "sha512-PtTRNpNm/5c746jRgZCNg4X9xEJIwggkGJrF0GP9AB1ANg4pc/sF2Fvn1NtqPe9wtQ2stunJprnm5WkCHN7QiA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "3.667.0", + "@smithy/types": "^3.5.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/middleware-recursion-detection": { + "version": "3.667.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-recursion-detection/-/middleware-recursion-detection-3.667.0.tgz", + "integrity": "sha512-U5glWD3ehFohzpUpopLtmqAlDurGWo2wRGPNgi4SwhWU7UDt6LS7E/UvJjqC0CUrjlzOw+my2A+Ncf+fisMhxQ==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "3.667.0", + "@smithy/protocol-http": "^4.1.4", + "@smithy/types": "^3.5.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/middleware-user-agent": { + "version": "3.668.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-user-agent/-/middleware-user-agent-3.668.0.tgz", + "integrity": "sha512-6WSCeN9AZZM/bM1kXJluLPFptd6z+tMBEZw3J7m1EvJSBTKEoSHiBrZBjc3gi83l/EKHCswITm2c8NcdgXAnLw==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/core": "3.667.0", + "@aws-sdk/types": "3.667.0", + "@aws-sdk/util-endpoints": "3.667.0", + "@smithy/core": "^2.4.8", + "@smithy/protocol-http": "^4.1.4", + "@smithy/types": "^3.5.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/region-config-resolver": { + "version": "3.667.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/region-config-resolver/-/region-config-resolver-3.667.0.tgz", + "integrity": "sha512-iNr+JhhA902JMKHG9IwT9YdaEx6KGl6vjAL5BRNeOjfj4cZYMog6Lz/IlfOAltMtT0w88DAHDEFrBd2uO0l2eg==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "3.667.0", + "@smithy/node-config-provider": "^3.1.8", + "@smithy/types": "^3.5.0", + "@smithy/util-config-provider": "^3.0.0", + "@smithy/util-middleware": "^3.0.7", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/token-providers": { + "version": "3.667.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/token-providers/-/token-providers-3.667.0.tgz", + "integrity": "sha512-ZecJlG8p6D4UTYlBHwOWX6nknVtw/OBJ3yPXTSajBjhUlj9lE2xvejI8gl4rqkyLXk7z3bki+KR4tATbMaM9yg==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "3.667.0", + "@smithy/property-provider": "^3.1.7", + "@smithy/shared-ini-file-loader": "^3.1.8", + "@smithy/types": "^3.5.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + }, + "peerDependencies": { + "@aws-sdk/client-sso-oidc": "^3.667.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/types": { + "version": "3.667.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/types/-/types-3.667.0.tgz", + "integrity": "sha512-gYq0xCsqFfQaSL/yT1Gl1vIUjtsg7d7RhnUfsXaHt8xTxOKRTdH9GjbesBjXOzgOvB0W0vfssfreSNGFlOOMJg==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/types": "^3.5.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/util-endpoints": { + "version": "3.667.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/util-endpoints/-/util-endpoints-3.667.0.tgz", + "integrity": "sha512-X22SYDAuQJWnkF1/q17pkX3nGw5XMD9YEUbmt87vUnRq7iyJ3JOpl6UKOBeUBaL838wA5yzdbinmCITJ/VZ1QA==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "3.667.0", + "@smithy/types": "^3.5.0", + "@smithy/util-endpoints": "^2.1.3", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/util-user-agent-browser": { + "version": "3.667.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/util-user-agent-browser/-/util-user-agent-browser-3.667.0.tgz", + "integrity": "sha512-y1pKlNzNpxzddM0QSnfIfIbi3Z9LTag1VDjYyZRbEGGSVip2J00qKsET+979nRezWMyJgw5GPBQR3Y+rN+jh0Q==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/types": "3.667.0", + "@smithy/types": "^3.5.0", + "bowser": "^2.11.0", + "tslib": "^2.6.2" + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@aws-sdk/util-user-agent-node": { + "version": "3.668.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/util-user-agent-node/-/util-user-agent-node-3.668.0.tgz", + "integrity": "sha512-A27U+G/R5ekZhf6L2yVOX6/YQqmAxOiV61M+a9Jy1eG6YDOXueYUYXaHUkLWy15sNB0TPJNdsApn1rJdvHI0AQ==", + "license": "Apache-2.0", + "dependencies": { + "@aws-sdk/middleware-user-agent": "3.668.0", + "@aws-sdk/types": "3.667.0", + "@smithy/node-config-provider": "^3.1.8", + "@smithy/types": "^3.5.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + }, + "peerDependencies": { + "aws-crt": ">=1.0.0" + }, + "peerDependenciesMeta": { + "aws-crt": { + "optional": true + } + } + }, + "node_modules/@aws-sdk/client-bedrock-agent/node_modules/@smithy/util-utf8": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@smithy/util-utf8/-/util-utf8-3.0.0.tgz", + "integrity": "sha512-rUeT12bxFnplYDe815GXbq/oixEGHfRFFtcTF3YdDi/JaENIM6aSYYLJydG83UNzLXeRI5K8abYd/8Sp/QM0kA==", + "license": "Apache-2.0", + "dependencies": { + "@smithy/util-buffer-from": "^3.0.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + } + }, "node_modules/@aws-sdk/client-bedrock-runtime": { "version": "3.665.0", "resolved": "https://registry.npmjs.org/@aws-sdk/client-bedrock-runtime/-/client-bedrock-runtime-3.665.0.tgz", @@ -10027,6 +10571,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==", + "dev": true, "license": "ISC", "engines": { "node": ">= 4.0.0" @@ -10608,6 +11153,7 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, "license": "MIT", "dependencies": { "balanced-match": "^1.0.0", @@ -11210,6 +11756,7 @@ "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "dev": true, "license": "MIT" }, "node_modules/console-browserify": { @@ -13024,6 +13571,7 @@ "version": "9.1.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", + "dev": true, "license": "MIT", "dependencies": { "at-least-node": "^1.0.0", @@ -13316,6 +13864,7 @@ "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", + "dev": true, "license": "ISC" }, "node_modules/graphemer": { @@ -13665,6 +14214,7 @@ "version": "5.3.2", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", + "dev": true, "license": "MIT", "engines": { "node": ">= 4" @@ -14466,6 +15016,7 @@ "version": "6.1.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dev": true, "license": "MIT", "dependencies": { "universalify": "^2.0.0" @@ -15677,6 +16228,7 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, "license": "ISC", "dependencies": { "brace-expansion": "^1.1.7" @@ -16757,6 +17309,7 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -17751,6 +18304,7 @@ "version": "5.7.2", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", + "dev": true, "license": "ISC", "bin": { "semver": "bin/semver" @@ -19070,6 +19624,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "dev": true, "license": "MIT", "engines": { "node": ">= 10.0.0" @@ -20225,6 +20780,7 @@ "dependencies": { "@aws-cdk/aws-cognito-identitypool-alpha": "^2.154.1-alpha.0", "@aws-cdk/aws-lambda-python-alpha": "^2.154.1-alpha.0", + "@aws-sdk/client-bedrock-agent": "^3.614.0", "@aws-sdk/client-bedrock-agent-runtime": "^3.614.0", "@aws-sdk/client-bedrock-runtime": "^3.614.0", "@aws-sdk/client-dynamodb": "^3.614.0", @@ -20256,6 +20812,7 @@ } }, "packages/types": { + "name": "@types/generative-ai-use-cases-jp", "dependencies": { "@aws-sdk/client-bedrock-agent-runtime": "^3.549.0", "@aws-sdk/client-kendra": "^3.549.0" diff --git a/packages/cdk/bin/generative-ai-use-cases.ts b/packages/cdk/bin/generative-ai-use-cases.ts index 49de0183..02015223 100644 --- a/packages/cdk/bin/generative-ai-use-cases.ts +++ b/packages/cdk/bin/generative-ai-use-cases.ts @@ -98,14 +98,6 @@ const anonymousUsageTracking: boolean = !!app.node.tryGetContext( 'anonymousUsageTracking' ); -const vpcId = app.node.tryGetContext('vpcId'); -if (typeof vpcId != 'undefined' && vpcId != null && typeof vpcId != 'string') { - throw new Error('vpcId must be string or undefined'); -} -if (typeof vpcId == 'string' && !vpcId.match(/^vpc-/)) { - throw new Error('vpcId must start with "vpc-"'); -} - const modelRegion: string = app.node.tryGetContext('modelRegion')!; // RAG Knowledge Base @@ -164,7 +156,6 @@ const generativeAiUseCasesStack = new GenerativeAiUseCasesStack( allowedIpV4AddressRanges, allowedIpV6AddressRanges, allowedCountryCodes, - vpcId, description: anonymousUsageTracking ? 'Generative AI Use Cases JP (uksb-1tupboc48)' : undefined, diff --git a/packages/cdk/cdk.json b/packages/cdk/cdk.json index 8a609f32..39a073f3 100644 --- a/packages/cdk/cdk.json +++ b/packages/cdk/cdk.json @@ -55,9 +55,7 @@ "hostedZoneId": null, "dashboard": false, "anonymousUsageTracking": true, - "recognizeFileEnabled": false, "guardrailEnabled" : false, - "vpcId": null, "crossAccountBedrockRoleArn": "", "@aws-cdk/aws-lambda:recognizeLayerVersion": true, "@aws-cdk/core:checkSecretUsage": true, @@ -96,4 +94,4 @@ "@aws-cdk/core:includePrefixInUniqueNameGeneration": true, "@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true } -} \ No newline at end of file +} diff --git a/packages/cdk/ecs/recognize-file/Dockerfile b/packages/cdk/ecs/recognize-file/Dockerfile deleted file mode 100644 index 2f1629b2..00000000 --- a/packages/cdk/ecs/recognize-file/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM public.ecr.aws/docker/library/python:3.11.6-slim-bookworm - -RUN apt-get update && apt-get install -y \ - build-essential cmake \ - # opencv package requirements - libgl1 \ - libglib2.0-0 \ - # unstructured package requirements for file type detection - libmagic-mgc libmagic1 \ - && rm -rf /var/lib/apt/lists/* - -WORKDIR /backend - -COPY requirements.txt . -RUN pip3 install -r requirements.txt --no-cache-dir - -COPY ./app ./app - -CMD ["uvicorn", "app.main:app", "--reload", "--host", "0.0.0.0", "--port", "80"] \ No newline at end of file diff --git a/packages/cdk/ecs/recognize-file/app/main.py b/packages/cdk/ecs/recognize-file/app/main.py deleted file mode 100644 index 3be3b8cf..00000000 --- a/packages/cdk/ecs/recognize-file/app/main.py +++ /dev/null @@ -1,60 +0,0 @@ -import boto3 -from fastapi import FastAPI, status -from fastapi.middleware.cors import CORSMiddleware -from fastapi.responses import JSONResponse -import os -from pydantic import BaseModel, ConfigDict -from pydantic.alias_generators import to_camel -import tempfile -from unstructured.partition.auto import partition -from urllib.parse import urlparse - -app = FastAPI() - -app.add_middleware( - CORSMiddleware, - allow_origins=['*'], - allow_methods=["*"], - allow_headers=["*"], -) - - -s3 = boto3.client('s3') - - -def parse_s3_url(s3_url): - # 仮想ホスト形式の URL から、bucket, key, suffix を抽出する - # 例) https://bucket-name.s3.ap-northeast-1.amazonaws.com/key.txt - # bucket -> bucket-name, key -> key.txt, suffix -> .txt - url = urlparse(s3_url) - - bucket = url.netloc.split('.')[0] - key = url.path.lstrip('/') - suffix = os.path.splitext(key)[1] - - return bucket, key, suffix - - -class BaseSchema(BaseModel): - model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True) - - -class ReadFileRequest(BaseSchema): - file_url: str - - -@app.post("/") -def read_file(req: ReadFileRequest): - bucket, key, suffix = parse_s3_url(req.file_url) - - text = '' - - with tempfile.NamedTemporaryFile(delete=True, suffix=suffix) as temp_file: - temp_file_path = temp_file.name - s3.download_file(bucket, key, temp_file_path) - - elements = partition(filename=temp_file_path) - texts = [el.text for el in elements] - text = ' '.join(texts) - - return JSONResponse(content={'text': text}, status_code=status.HTTP_200_OK) diff --git a/packages/cdk/ecs/recognize-file/requirements.txt b/packages/cdk/ecs/recognize-file/requirements.txt deleted file mode 100644 index 30272309..00000000 --- a/packages/cdk/ecs/recognize-file/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -boto3 -fastapi -unstructured[csv,doc,docx,md,pdf,ppt,pptx,tsv,xlsx] -uvicorn \ No newline at end of file diff --git a/packages/cdk/lambda/utils/bedrockAgentApi.ts b/packages/cdk/lambda/utils/bedrockAgentApi.ts index ebec77b0..60f04ada 100644 --- a/packages/cdk/lambda/utils/bedrockAgentApi.ts +++ b/packages/cdk/lambda/utils/bedrockAgentApi.ts @@ -1,3 +1,8 @@ +import { + BedrockAgentClient, + GetAgentAliasCommand, + ListAgentActionGroupsCommand, +} from '@aws-sdk/client-bedrock-agent'; import { BedrockAgentRuntimeClient, DependencyFailedException, @@ -18,12 +23,21 @@ import { } from 'generative-ai-use-cases-jp'; import { streamingChunk } from './streamingChunk'; -const agentMap: AgentMap = JSON.parse(process.env.AGENT_MAP || '{}'); -const client = new BedrockAgentRuntimeClient({ +const agentClient = new BedrockAgentClient({ + region: process.env.AGENT_REGION, +}); +const agentRuntimeClient = new BedrockAgentRuntimeClient({ region: process.env.AGENT_REGION, }); const s3Client = new S3Client({}); +// Agent の情報 +const agentMap: AgentMap = JSON.parse(process.env.AGENT_MAP || '{}'); +type AgentInfo = { + codeInterpreterEnabled: boolean; +}; +const agentInfoMap: { [aliasId: string]: AgentInfo } = {}; + // s3:/// から https://.s3.amazonaws.com/ に変換する const convertS3UriToUrl = (s3Uri: string): string => { const result = /^s3:\/\/(?.+?)\/(?.+)/.exec(s3Uri); @@ -37,9 +51,48 @@ const convertS3UriToUrl = (s3Uri: string): string => { return ''; }; +const getAgentInfo = async (agentId: string, agentAliasId: string) => { + // Get Agent Info if not cached + if (!agentInfoMap[agentAliasId]) { + // Get Agent Version + const agentAliasInfoRes = await agentClient.send( + new GetAgentAliasCommand({ + agentId: agentId, + agentAliasId: agentAliasId, + }) + ); + const agentVersion = + agentAliasInfoRes.agentAlias?.routingConfiguration?.pop()?.agentVersion ?? + '1'; + // List Action Group + const actionGroups = await agentClient.send( + new ListAgentActionGroupsCommand({ + agentId: agentId, + agentVersion: agentVersion, + }) + ); + // Cache Agent Info + agentInfoMap[agentAliasId] = { + codeInterpreterEnabled: !!actionGroups.actionGroupSummaries?.find( + (actionGroup) => actionGroup.actionGroupName === 'CodeInterpreterAction' + ), + }; + } + return agentInfoMap[agentAliasId]; +}; + const bedrockAgentApi: Pick = { invokeStream: async function* (model: Model, messages: UnrecordedMessage[]) { try { + // Get Agent + if (!agentMap[model.modelId]) { + throw new Error('Agent not found'); + } + const agentId = agentMap[model.modelId].agentId; + const agentAliasId = agentMap[model.modelId].aliasId; + const agentInfo = await getAgentInfo(agentId, agentAliasId); + + // Invoke Agent const command = new InvokeAgentCommand({ sessionState: { files: @@ -52,16 +105,18 @@ const bedrockAgentApi: Pick = { data: Buffer.from(file.source.data, 'base64'), }, }, - useCase: 'CODE_INTERPRETER', + useCase: agentInfo.codeInterpreterEnabled + ? 'CODE_INTERPRETER' + : 'CHAT', })) || [], }, - agentId: agentMap[model.modelId].agentId, - agentAliasId: agentMap[model.modelId].aliasId, + agentId: agentId, + agentAliasId: agentAliasId, sessionId: model.sessionId, enableTrace: true, inputText: messages[messages.length - 1].content, }); - const res = await client.send(command); + const res = await agentRuntimeClient.send(command); if (!res.completion) { return; diff --git a/packages/cdk/lambda/utils/models.ts b/packages/cdk/lambda/utils/models.ts index 2eda61d4..f48f2ebf 100644 --- a/packages/cdk/lambda/utils/models.ts +++ b/packages/cdk/lambda/utils/models.ts @@ -10,6 +10,8 @@ import { UsecaseConverseInferenceParams, GuardrailConverseConfigParams, GuardrailConverseStreamConfigParams, + StabilityAI2024ModelParams, + StabilityAI2024ModelResponse, } from 'generative-ai-use-cases-jp'; import { ConverseCommandInput, @@ -379,6 +381,54 @@ const createBodyImageStableDiffusion = (params: GenerateImageParams) => { return JSON.stringify(body); }; +const createBodyImageStabilityAI2024Model = (params: GenerateImageParams) => { + let positivePrompt: string = ''; + let negativePrompt: string | undefined; + params.textPrompt.forEach((prompt) => { + if (prompt.weight >= 0) { + positivePrompt = prompt.text; + } else { + negativePrompt = prompt.text; + } + }); + if (!positivePrompt) { + throw new Error('Positive prompt is required'); + } + let body: StabilityAI2024ModelParams = { + prompt: positivePrompt, + seed: params.seed, + output_format: 'png', + }; + if (params.stylePreset) { + body.prompt = body.prompt + ', ' + params.stylePreset; + } + + // image-to-image modeの際、aspect比を使用できない + if (params.aspectRatio && !params.initImage) { + body = { + ...body, + aspect_ratio: params.aspectRatio, + }; + } + if (negativePrompt) { + body = { + ...body, + negative_prompt: negativePrompt, + }; + } + + // Image to Image + if (params.initImage) { + body = { + ...body, + image: params.initImage, + mode: 'image-to-image', + strength: params.imageStrength, + }; + } + return JSON.stringify(body); +}; + const createBodyImageTitanImage = (params: GenerateImageParams) => { // TODO: Support inpainting and outpainting too const imageGenerationConfig = { @@ -452,20 +502,50 @@ const createBodyImageTitanImage = (params: GenerateImageParams) => { }; const extractOutputImageStableDiffusion = ( - response: BedrockImageGenerationResponse + response: BedrockImageGenerationResponse | StabilityAI2024ModelResponse ) => { - if (response.result !== 'success') { - throw new Error('Failed to invoke model'); + if ('result' in response) { + // BedrockImageGenerationResponse の場合 + if (response.result !== 'success') { + throw new Error('Failed to invoke model'); + } + return response.artifacts[0].base64; + } else { + // StabilityAI2024ModelResponse の場合 + throw new Error('Unexpected response type for Stable Diffusion'); } - return response.artifacts[0].base64; }; -const extractOutputImageTitanImage = ( - response: BedrockImageGenerationResponse +const extractOutputImageStabilityAI2024Model = ( + response: BedrockImageGenerationResponse | StabilityAI2024ModelResponse ) => { - return response.images[0]; + if ('finish_reasons' in response) { + // StabilityAI2024ModelResponse の場合 + if (response.finish_reasons[0] !== null) { + if (response.finish_reasons[0] == 'Filter reason: prompt') { + throw new Error( + response.finish_reasons[0] + + ': 日本語のプロンプトには対応していません' + ); + } + throw new Error(response.finish_reasons[0]); + } + return response.images[0]; + } else { + // BedrockImageGenerationResponse の場合 + throw new Error('Unexpected response type for Stability AI 2024 Model'); + } }; +const extractOutputImageTitanImage = ( + response: BedrockImageGenerationResponse | StabilityAI2024ModelResponse +) => { + if ('images' in response) { + return response.images[0]; + } else { + throw new Error('Unexpected response type for Titan Image'); + } +}; // テキスト生成に関する、各のModel のパラメーターや関数の定義 export const BEDROCK_TEXT_GEN_MODELS: { @@ -490,6 +570,14 @@ export const BEDROCK_TEXT_GEN_MODELS: { extractConverseStreamOutputText: (body: ConverseStreamOutput) => string; }; } = { + 'anthropic.claude-3-5-sonnet-20241022-v2:0': { + defaultParams: CLAUDE_DEFAULT_PARAMS, + usecaseParams: USECASE_DEFAULT_PARAMS, + createConverseCommandInput: createConverseCommandInput, + createConverseStreamCommandInput: createConverseStreamCommandInput, + extractConverseOutputText: extractConverseOutputText, + extractConverseStreamOutputText: extractConverseStreamOutputText, + }, 'anthropic.claude-3-5-sonnet-20240620-v1:0': { defaultParams: CLAUDE_DEFAULT_PARAMS, usecaseParams: USECASE_DEFAULT_PARAMS, @@ -773,13 +861,27 @@ export const BEDROCK_TEXT_GEN_MODELS: { export const BEDROCK_IMAGE_GEN_MODELS: { [key: string]: { createBodyImage: (params: GenerateImageParams) => string; - extractOutputImage: (response: BedrockImageGenerationResponse) => string; + extractOutputImage: ( + response: BedrockImageGenerationResponse | StabilityAI2024ModelResponse + ) => string; }; } = { 'stability.stable-diffusion-xl-v1': { createBodyImage: createBodyImageStableDiffusion, extractOutputImage: extractOutputImageStableDiffusion, }, + 'stability.sd3-large-v1:0': { + createBodyImage: createBodyImageStabilityAI2024Model, + extractOutputImage: extractOutputImageStabilityAI2024Model, + }, + 'stability.stable-image-core-v1:0': { + createBodyImage: createBodyImageStabilityAI2024Model, + extractOutputImage: extractOutputImageStabilityAI2024Model, + }, + 'stability.stable-image-ultra-v1:0': { + createBodyImage: createBodyImageStabilityAI2024Model, + extractOutputImage: extractOutputImageStabilityAI2024Model, + }, 'amazon.titan-image-generator-v1': { createBodyImage: createBodyImageTitanImage, extractOutputImage: extractOutputImageTitanImage, diff --git a/packages/cdk/lib/construct/api.ts b/packages/cdk/lib/construct/api.ts index 07fff102..4f318c93 100644 --- a/packages/cdk/lib/construct/api.ts +++ b/packages/cdk/lib/construct/api.ts @@ -72,6 +72,7 @@ export class Api extends Construct { // Validate Model Names const supportedModelIds = [ + 'anthropic.claude-3-5-sonnet-20241022-v2:0', 'anthropic.claude-3-5-sonnet-20240620-v1:0', 'anthropic.claude-3-opus-20240229-v1:0', 'anthropic.claude-3-sonnet-20240229-v1:0', @@ -90,6 +91,9 @@ export class Api extends Construct { // 'amazon.titan-text-express-v1', 'amazon.titan-text-premier-v1:0', 'stability.stable-diffusion-xl-v1', + 'stability.sd3-large-v1:0', + 'stability.stable-image-core-v1:0', + 'stability.stable-image-ultra-v1:0', 'amazon.titan-image-generator-v2:0', 'amazon.titan-image-generator-v1', 'meta.llama3-8b-instruct-v1:0', @@ -112,6 +116,7 @@ export class Api extends Construct { 'cohere.command-r-plus-v1:0', ]; const multiModalModelIds = [ + 'anthropic.claude-3-5-sonnet-20241022-v2:0', 'anthropic.claude-3-5-sonnet-20240620-v1:0', 'anthropic.claude-3-opus-20240229-v1:0', 'anthropic.claude-3-sonnet-20240229-v1:0', diff --git a/packages/cdk/lib/construct/common-web-acl.ts b/packages/cdk/lib/construct/common-web-acl.ts index 805f327c..94bfa648 100644 --- a/packages/cdk/lib/construct/common-web-acl.ts +++ b/packages/cdk/lib/construct/common-web-acl.ts @@ -104,7 +104,7 @@ export class CommonWebAcl extends Construct { const wafIPv6Set = new CfnIPSet(this, `IPv6Set${id}`, { ipAddressVersion: 'IPV6', scope: props.scope, - addresses: props.allowedIpV4AddressRanges ?? [], + addresses: props.allowedIpV6AddressRanges ?? [], }); if (hasAllowedCountryCodes) { // Geo制限を行う場合は、IP制限とのAND条件にする diff --git a/packages/cdk/lib/construct/index.ts b/packages/cdk/lib/construct/index.ts index 293fde58..1504de3f 100644 --- a/packages/cdk/lib/construct/index.ts +++ b/packages/cdk/lib/construct/index.ts @@ -6,6 +6,5 @@ export * from './rag'; export * from './transcribe'; export * from './common-web-acl'; export * from './agent'; -export * from './recognize-file'; export * from './rag-knowledge-base'; export * from './guardrail'; diff --git a/packages/cdk/lib/construct/rag.ts b/packages/cdk/lib/construct/rag.ts index b38530b4..a4dfeb13 100644 --- a/packages/cdk/lib/construct/rag.ts +++ b/packages/cdk/lib/construct/rag.ts @@ -146,6 +146,19 @@ export class Rag extends Construct { iam.ManagedPolicy.fromAwsManagedPolicyName('CloudWatchLogsFullAccess') ); + const accessLogsBucket = new s3.Bucket( + this, + 'DataSourceAccessLogsBucket', + { + blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, + encryption: s3.BucketEncryption.S3_MANAGED, + autoDeleteObjects: true, + removalPolicy: RemovalPolicy.DESTROY, + objectOwnership: s3.ObjectOwnership.OBJECT_WRITER, + enforceSSL: true, + } + ); + // .pdf や .txt などのドキュメントを格納する S3 Bucket dataSourceBucket = new s3.Bucket(this, 'DataSourceBucket', { blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, @@ -153,6 +166,7 @@ export class Rag extends Construct { autoDeleteObjects: true, removalPolicy: RemovalPolicy.DESTROY, objectOwnership: s3.ObjectOwnership.OBJECT_WRITER, + serverAccessLogsBucket: accessLogsBucket, serverAccessLogsPrefix: 'AccessLogs/', enforceSSL: true, }); @@ -161,6 +175,7 @@ export class Rag extends Construct { new s3Deploy.BucketDeployment(this, 'DeployDocs', { sources: [s3Deploy.Source.asset('./rag-docs')], destinationBucket: dataSourceBucket, + // 以前の設定で同 Bucket にアクセスログが残っている可能性があるため、この設定は残す exclude: ['AccessLogs/*'], }); diff --git a/packages/cdk/lib/construct/recognize-file.ts b/packages/cdk/lib/construct/recognize-file.ts deleted file mode 100644 index ee6964da..00000000 --- a/packages/cdk/lib/construct/recognize-file.ts +++ /dev/null @@ -1,169 +0,0 @@ -import { RemovalPolicy } from 'aws-cdk-lib'; -import { - AuthorizationType, - CfnMethod, - CfnStage, - CognitoUserPoolsAuthorizer, - ConnectionType, - Integration, - IntegrationType, - RestApi, - VpcLink, -} from 'aws-cdk-lib/aws-apigateway'; -import { UserPool } from 'aws-cdk-lib/aws-cognito'; -import { Effect, PolicyStatement } from 'aws-cdk-lib/aws-iam'; -import { Bucket } from 'aws-cdk-lib/aws-s3'; -import { Construct } from 'constructs'; -import { Platform } from 'aws-cdk-lib/aws-ecr-assets'; -import { IVpc, Peer, Port, SubnetType, Vpc } from 'aws-cdk-lib/aws-ec2'; -import { - Cluster, - ContainerImage, - CpuArchitecture, - FargateTaskDefinition, - LogDriver, - OperatingSystemFamily, - Protocol, -} from 'aws-cdk-lib/aws-ecs'; -import { LogGroup } from 'aws-cdk-lib/aws-logs'; -import { NetworkLoadBalancedFargateService } from 'aws-cdk-lib/aws-ecs-patterns'; -import { ServiceLinkedRole } from 'upsert-slr'; - -export interface RecognizeFileProps { - userPool: UserPool; - api: RestApi; - fileBucket: Bucket; - vpcId?: string; -} - -export class RecognizeFile extends Construct { - constructor(scope: Construct, id: string, props: RecognizeFileProps) { - super(scope, id); - - const stage = props.api.deploymentStage.node.defaultChild as CfnStage; - - const authorizer = new CognitoUserPoolsAuthorizer(this, 'Authorizer', { - cognitoUserPools: [props.userPool], - }); - - const commonAuthorizerProps = { - authorizationType: AuthorizationType.COGNITO, - authorizer, - }; - - const fileResource = - props.api.root.getResource('file') || props.api.root.addResource('file'); - - // VPC - let vpc: IVpc; - if (props.vpcId) { - vpc = Vpc.fromLookup(this, 'Vpc', { vpcId: props.vpcId }); - } else { - vpc = new Vpc(this, 'Vpc', { - maxAzs: 2, - }); - } - // ECS - const cluster = new Cluster(this, 'Cluster', { - vpc: vpc, - }); - - new ServiceLinkedRole(this, 'EcsServiceLinkedRole', { - awsServiceName: 'ecs.amazonaws.com', - }); - - const taskDefinition = new FargateTaskDefinition(this, 'TaskDefinition', { - cpu: 2048, - memoryLimitMiB: 4096, - runtimePlatform: { - cpuArchitecture: CpuArchitecture.X86_64, - operatingSystemFamily: OperatingSystemFamily.LINUX, - }, - }); - - taskDefinition.addToTaskRolePolicy( - new PolicyStatement({ - effect: Effect.ALLOW, - actions: ['s3:GetObject'], - resources: [props.fileBucket.arnForObjects('*')], - }) - ); - - const taskLogGroup = new LogGroup(this, 'TaskLogGroup', { - removalPolicy: RemovalPolicy.DESTROY, - }); - - const container = taskDefinition.addContainer('Container', { - image: ContainerImage.fromAsset('ecs/recognize-file', { - platform: Platform.LINUX_AMD64, - }), - logging: LogDriver.awsLogs({ - streamPrefix: 'recognize-file', - logGroup: taskLogGroup, - }), - }); - - container.addPortMappings({ - protocol: Protocol.TCP, - containerPort: 80, - hostPort: 80, - }); - - taskLogGroup.grantWrite(container.taskDefinition.executionRole!); - - // NLB - const loadBalancedFargateService = new NetworkLoadBalancedFargateService( - this, - 'LoadBalancedFargateService', - { - cluster: cluster, - memoryLimitMiB: 1024, - cpu: 512, - taskDefinition: taskDefinition, - publicLoadBalancer: false, - taskSubnets: vpc.selectSubnets({ - subnetType: SubnetType.PRIVATE_WITH_EGRESS, - }), - } - ); - - loadBalancedFargateService.service.connections.allowFrom( - Peer.ipv4(vpc.vpcCidrBlock), - Port.tcp(80) - ); - - // VPC Link - const link = new VpcLink(this, 'link', { - targets: [loadBalancedFargateService.loadBalancer], - }); - - // API Gateway - stage.variables = { - vpcLinkId: link.vpcLinkId, - }; - - // POST: /file/recognize - const recognizeMethod = fileResource.addResource('recognize').addMethod( - 'POST', - new Integration({ - type: IntegrationType.HTTP_PROXY, - integrationHttpMethod: 'POST', - options: { - connectionType: ConnectionType.VPC_LINK, - vpcLink: link, - }, - }), - commonAuthorizerProps - ); - - // REST API の Method で VPC Link を参照すると、正しく削除できない問題がある。 - // ステージ変数を利用するとその問題を回避できるため、ConnectionId (ここでは VPC Link ID) をステージ変数経由で使うように変更している。 - // (L2 Construct では ConnectionId を設定できないため、L1 Construct のプロパティを直接変更している) - // 参考: https://docs.aws.amazon.com/ja_jp/apigateway/latest/developerguide/api-gateway-known-issues.html - const cfnRecognizeMethod = recognizeMethod.node.defaultChild as CfnMethod; - cfnRecognizeMethod.addPropertyOverride( - 'Integration.ConnectionId', - '${stageVariables.vpcLinkId}' - ); - } -} diff --git a/packages/cdk/lib/construct/web.ts b/packages/cdk/lib/construct/web.ts index ff2bebd5..49738d0c 100644 --- a/packages/cdk/lib/construct/web.ts +++ b/packages/cdk/lib/construct/web.ts @@ -34,7 +34,6 @@ export interface WebProps { samlCognitoDomainName: string; samlCognitoFederatedIdentityProviderName: string; agentNames: string[]; - recognizeFileEnabled: boolean; cert?: ICertificate; hostName?: string; domainName?: string; @@ -187,7 +186,6 @@ export class Web extends Construct { VITE_APP_SAML_COGNITO_FEDERATED_IDENTITY_PROVIDER_NAME: props.samlCognitoFederatedIdentityProviderName.toString(), VITE_APP_AGENT_NAMES: JSON.stringify(props.agentNames), - VITE_APP_RECOGNIZE_FILE_ENABLED: props.recognizeFileEnabled.toString(), }, }); diff --git a/packages/cdk/lib/generative-ai-use-cases-stack.ts b/packages/cdk/lib/generative-ai-use-cases-stack.ts index 69a0b91a..c28e9380 100644 --- a/packages/cdk/lib/generative-ai-use-cases-stack.ts +++ b/packages/cdk/lib/generative-ai-use-cases-stack.ts @@ -9,7 +9,6 @@ import { RagKnowledgeBase, Transcribe, CommonWebAcl, - RecognizeFile, } from './construct'; import { CfnWebACLAssociation } from 'aws-cdk-lib/aws-wafv2'; import * as cognito from 'aws-cdk-lib/aws-cognito'; @@ -28,7 +27,6 @@ interface GenerativeAiUseCasesStackProps extends StackProps { allowedIpV4AddressRanges: string[] | null; allowedIpV6AddressRanges: string[] | null; allowedCountryCodes: string[] | null; - vpcId?: string; cert?: ICertificate; hostName?: string; domainName?: string; @@ -71,9 +69,7 @@ export class GenerativeAiUseCasesStack extends Stack { this.node.tryGetContext('samlCognitoFederatedIdentityProviderName')!; const agentEnabled = this.node.tryGetContext('agentEnabled') || false; const promptFlows = this.node.tryGetContext('promptFlows') || []; - const recognizeFileEnabled: boolean = this.node.tryGetContext( - 'recognizeFileEnabled' - )!; + const guardrailEnabled: boolean = this.node.tryGetContext('guardrailEnabled') || false; @@ -93,10 +89,6 @@ export class GenerativeAiUseCasesStack extends Stack { throw new Error(errorMessageForBooleanContext('samlAuthEnabled')); } - if (typeof recognizeFileEnabled !== 'boolean') { - throw new Error(errorMessageForBooleanContext('recognizeFileEnabled')); - } - if (typeof guardrailEnabled !== 'boolean') { throw new Error( errorMessageForBooleanContext('guardrailsForAmazonBedrockEnabled') @@ -165,7 +157,6 @@ export class GenerativeAiUseCasesStack extends Stack { samlCognitoDomainName, samlCognitoFederatedIdentityProviderName, agentNames: api.agentNames, - recognizeFileEnabled, cert: props.cert, hostName: props.hostName, domainName: props.domainName, @@ -204,15 +195,6 @@ export class GenerativeAiUseCasesStack extends Stack { api: api.api, }); - if (recognizeFileEnabled) { - new RecognizeFile(this, 'RecognizeFile', { - userPool: auth.userPool, - api: api.api, - fileBucket: api.fileBucket, - vpcId: props.vpcId, - }); - } - new CfnOutput(this, 'Region', { value: this.region, }); @@ -303,10 +285,6 @@ export class GenerativeAiUseCasesStack extends Stack { value: JSON.stringify(api.agentNames), }); - new CfnOutput(this, 'RecognizeFileEnabled', { - value: recognizeFileEnabled.toString(), - }); - this.userPool = auth.userPool; this.userPoolClient = auth.client; } diff --git a/packages/cdk/lib/rag-knowledge-base-stack.ts b/packages/cdk/lib/rag-knowledge-base-stack.ts index 8c99f4fe..d9399ec2 100644 --- a/packages/cdk/lib/rag-knowledge-base-stack.ts +++ b/packages/cdk/lib/rag-knowledge-base-stack.ts @@ -1,4 +1,4 @@ -import { Stack, StackProps } from 'aws-cdk-lib'; +import { Stack, StackProps, RemovalPolicy } from 'aws-cdk-lib'; import { Construct } from 'constructs'; import * as cdk from 'aws-cdk-lib'; import * as lambda from 'aws-cdk-lib/aws-lambda'; @@ -283,12 +283,22 @@ export class RagKnowledgeBaseStack extends Stack { collection.node.addDependency(networkPolicy); collection.node.addDependency(encryptionPolicy); + const accessLogsBucket = new s3.Bucket(this, 'DataSourceAccessLogsBucket', { + blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, + encryption: s3.BucketEncryption.S3_MANAGED, + autoDeleteObjects: true, + removalPolicy: RemovalPolicy.DESTROY, + objectOwnership: s3.ObjectOwnership.OBJECT_WRITER, + enforceSSL: true, + }); + const dataSourceBucket = new s3.Bucket(this, 'DataSourceBucket', { blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, encryption: s3.BucketEncryption.S3_MANAGED, autoDeleteObjects: true, removalPolicy: cdk.RemovalPolicy.DESTROY, objectOwnership: s3.ObjectOwnership.OBJECT_WRITER, + serverAccessLogsBucket: accessLogsBucket, serverAccessLogsPrefix: 'AccessLogs/', enforceSSL: true, }); @@ -426,6 +436,7 @@ export class RagKnowledgeBaseStack extends Stack { new s3Deploy.BucketDeployment(this, 'DeployDocs', { sources: [s3Deploy.Source.asset('./rag-docs')], destinationBucket: dataSourceBucket, + // 以前の設定で同 Bucket にアクセスログが残っている可能性があるため、この設定は残す exclude: ['AccessLogs/*'], }); diff --git a/packages/cdk/package.json b/packages/cdk/package.json index 455687c2..3dbb139b 100644 --- a/packages/cdk/package.json +++ b/packages/cdk/package.json @@ -21,6 +21,7 @@ "dependencies": { "@aws-cdk/aws-cognito-identitypool-alpha": "^2.154.1-alpha.0", "@aws-cdk/aws-lambda-python-alpha": "^2.154.1-alpha.0", + "@aws-sdk/client-bedrock-agent": "^3.614.0", "@aws-sdk/client-bedrock-agent-runtime": "^3.614.0", "@aws-sdk/client-bedrock-runtime": "^3.614.0", "@aws-sdk/client-dynamodb": "^3.614.0", diff --git a/packages/types/src/image.d.ts b/packages/types/src/image.d.ts index f8e5d112..5a8a5101 100644 --- a/packages/types/src/image.d.ts +++ b/packages/types/src/image.d.ts @@ -11,6 +11,7 @@ export type GenerateImageParams = { imageStrength?: number; height: number; width: number; + aspectRatio?: string; // Image to Image initImage?: string; // Inpaint / Outpaint @@ -44,6 +45,18 @@ export type StableDiffusionParams = { mask_image?: string; }; +export type StabilityAI2024ModelParams = { + prompt: string; + negative_prompt?: string; + aspect_ratio?: string; + seed?: number; + output_format?: string; + // Image to Image + image?: string; + mode?: string; + strength?: number; +}; + // Titan Image // https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-titan-image.html export type TitanImageParams = { @@ -90,3 +103,9 @@ export type BedrockImageGenerationResponse = { }[]; images: string[]; }; + +export type StabilityAI2024ModelResponse = { + seeds: string[]; + finish_reasons: (string | null)[]; + images: string[]; +}; diff --git a/packages/types/src/protocol.d.ts b/packages/types/src/protocol.d.ts index 5a0c1ecb..e51f3a1a 100644 --- a/packages/types/src/protocol.d.ts +++ b/packages/types/src/protocol.d.ts @@ -195,11 +195,3 @@ export type GetFileUploadSignedUrlResponse = string; export type UploadFileRequest = { file: File; }; - -export type RecognizeFileRequest = { - fileUrl: string; -}; - -export type RecognizeFileResponse = { - text: string; -}; diff --git a/packages/web/src/App.tsx b/packages/web/src/App.tsx index 97db3234..a4734df1 100644 --- a/packages/web/src/App.tsx +++ b/packages/web/src/App.tsx @@ -16,7 +16,6 @@ import { PiGlobe, PiX, PiRobot, - PiUploadSimple, PiVideoCamera, PiFlowArrow, } from 'react-icons/pi'; @@ -35,8 +34,6 @@ const ragEnabled: boolean = import.meta.env.VITE_APP_RAG_ENABLED === 'true'; const ragKnowledgeBaseEnabled: boolean = import.meta.env.VITE_APP_RAG_KNOWLEDGE_BASE_ENABLED === 'true'; const agentEnabled: boolean = import.meta.env.VITE_APP_AGENT_ENABLED === 'true'; -const recognizeFileEnabled: boolean = - import.meta.env.VITE_APP_RECOGNIZE_FILE_ENABLED === 'true'; const { multiModalModelIds } = MODELS; const multiModalEnabled: boolean = multiModalModelIds.length > 0; const getPromptFlows = () => { @@ -152,15 +149,6 @@ const items: ItemProps[] = [ icon: , display: 'tool' as const, }, - recognizeFileEnabled - ? { - label: 'ファイルアップロード', - to: '/file', - icon: , - display: 'tool' as const, - sub: 'Deprecated', - } - : null, ragEnabled ? { label: 'Kendra 検索', diff --git a/packages/web/src/components/ButtonFeedback.tsx b/packages/web/src/components/ButtonFeedback.tsx index e449679e..e0244879 100644 --- a/packages/web/src/components/ButtonFeedback.tsx +++ b/packages/web/src/components/ButtonFeedback.tsx @@ -55,4 +55,4 @@ const ButtonFeedback: React.FC = (props) => { ); }; -export default ButtonFeedback; \ No newline at end of file +export default ButtonFeedback; diff --git a/packages/web/src/components/ChatMessage.tsx b/packages/web/src/components/ChatMessage.tsx index d0ff4369..eebaf8f1 100644 --- a/packages/web/src/components/ChatMessage.tsx +++ b/packages/web/src/components/ChatMessage.tsx @@ -6,7 +6,10 @@ import ButtonFeedback from './ButtonFeedback'; import ZoomUpImage from './ZoomUpImage'; import { PiUserFill, PiChalkboardTeacher } from 'react-icons/pi'; import { BaseProps } from '../@types/common'; -import { ShownMessage, UpdateFeedbackRequest } from 'generative-ai-use-cases-jp'; +import { + ShownMessage, + UpdateFeedbackRequest, +} from 'generative-ai-use-cases-jp'; import BedrockIcon from '../assets/bedrock.svg?react'; import useChat from '../hooks/useChat'; import useTyping from '../hooks/useTyping'; @@ -74,8 +77,8 @@ const ChatMessage: React.FC = (props) => { await sendFeedback(feedbackData); } else { await sendFeedback({ - createdDate: props.chatContent!.createdDate!, - feedback: 'none' + createdDate: props.chatContent!.createdDate!, + feedback: 'none', }); setShowFeedbackForm(false); } @@ -87,25 +90,28 @@ const ChatMessage: React.FC = (props) => { // ボタン押した際、ユーザーからの詳細フィードバック前にDBに送る。 onSendFeedback({ createdDate: props.chatContent!.createdDate!, - feedback: feedback + feedback: feedback, }); if (feedback === 'bad' && chatContent?.feedback !== 'bad') { setShowFeedbackForm(true); } }; - const handleFeedbackFormSubmit = async (reasons: string[], detailedFeedback: string) => { + const handleFeedbackFormSubmit = async ( + reasons: string[], + detailedFeedback: string + ) => { await sendFeedback({ createdDate: props.chatContent!.createdDate!, feedback: 'bad', reasons: reasons, - detailedFeedback: detailedFeedback - }); + detailedFeedback: detailedFeedback, + }); setShowFeedbackForm(false); setShowThankYouMessage(true); setTimeout(() => { setShowThankYouMessage(false); - }, 3000); + }, 3000); }; const handleFeedbackFormCancel = () => { @@ -261,7 +267,7 @@ const ChatMessage: React.FC = (props) => { /> )} {showThankYouMessage && ( -
+
フィードバックを受け付けました。ありがとうございます。
)} diff --git a/packages/web/src/components/FeedbackForm.tsx b/packages/web/src/components/FeedbackForm.tsx index 3a556514..1fe30bfd 100644 --- a/packages/web/src/components/FeedbackForm.tsx +++ b/packages/web/src/components/FeedbackForm.tsx @@ -14,9 +14,9 @@ const FeedbackForm: React.FC = ({ onSubmit, onCancel }) => { const reasons = ['不正確', '情報が古い', '有害または攻撃的', 'その他']; const handleReasonChange = (reason: string) => { - setSelectedReasons(prev => - prev.includes(reason) - ? prev.filter(r => r !== reason) + setSelectedReasons((prev) => + prev.includes(reason) + ? prev.filter((r) => r !== reason) : [...prev, reason] ); setError(''); @@ -31,37 +31,42 @@ const FeedbackForm: React.FC = ({ onSubmit, onCancel }) => { }; return ( -
-

この回答を評価した理由をお聞かせください。

+
+

+ この回答を評価した理由をお聞かせください。 +

{reasons.map((reason) => ( ))}
- {error &&

{error}

} + {error &&

{error}

}