### Install Project Dependencies Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/事前準備.md Install all necessary project dependencies from the root directory using npm ci. ```bash npm ci ``` -------------------------------- ### Install Node.js using Mise Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/事前準備.md Use 'mise' to trust and install the Node.js version specified in the project. ```bash mise trust mise install ``` -------------------------------- ### Deployment Configuration Source: https://context7.com/digital-go-jp/genai-web/llms.txt Configuration examples for deploying infrastructure using AWS CDK. ```APIDOC ## AWS CDK Deployment Configuration ### Environment Parameters Example (`self-hosting-prod.ts`) This file defines the input parameters for the AWS CDK stack for a production self-hosted environment. ```typescript import { StackInput } from '../lib/stack-input'; export const selfHostingProdParams: Partial = { // Basic Settings appEnv: 'prod', logLevel: 'INFO', // Authentication Settings selfSignUpEnabled: false, samlAuthEnabled: true, samlCognitoDomainName: 'genai.auth.ap-northeast-1.amazoncognito.com', samlCognitoFederatedIdentityProviderName: 'EntraID', // Security Settings allowedIpV4AddressRanges: ['203.0.113.0/24', '198.51.100.0/24'], // Custom Domain hostName: 'genai', domainName: 'example.go.jp', hostedZoneId: 'Z1234567890ABC', certificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/xxx', // Model Settings modelRegion: 'ap-northeast-1', modelIds: [ 'jp.anthropic.claude-sonnet-4-5-20250929-v1:0', 'jp.anthropic.claude-haiku-4-5-20251001-v1:0', 'amazon.nova-pro-v1:0', 'amazon.nova-lite-v1:0' ], imageGenerationModelIds: ['amazon.nova-canvas-v1:0'], // Monitoring Settings monitoring: true, slack: { enabled: true, workspaceId: 'T01234567', channelId: 'C01234567' } }; ``` ### Registering Environment Parameters (`parameter.ts`) This shows how to register the environment parameters for deployment. ```typescript import { selfHostingProdParams } from './env-parameters/self-hosting-prod'; const deploy_envs: Record> = { '-prod': selfHostingProdParams, }; ``` ## Deployment Commands ### Deploy All Stacks ```bash npm -w packages/cdk run cdk -- deploy --all --require-approval never -c env=-prod ``` ### Deploy Specific Stack ```bash npm -w packages/cdk run cdk -- deploy GenAIWebStack-prod --require-approval never -c env=-prod ``` ### Destroy Stacks ```bash npm -w packages/cdk run cdk destroy -- --all -c env=-prod ``` ``` -------------------------------- ### Run Local Development Environment Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/ローカル開発環境.md Execute this command to start the local development server. Replace '環境名' with the appropriate environment name, such as '-dev'. ```shell sh scripts/run.sh 環境名(例: -dev) ``` -------------------------------- ### Sample Request Body Structure Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/AIアプリAPI仕様.md An example of how the input fields can be structured for the AI application. ```APIDOC ## Sample Request Body Structure ```json { "question": { "title": "Input", "desc": "Enter the content you want to ask.", "type": "text", "required": true, "default_value": "Default Value" }, "content": { "title": "Content", "desc": "Enter content in Markdown format.", "type": "textarea" }, "step": { "title": "Number Input Example", "type": "number", "required": true, "min": 10, "max": 1000, "default_value": 20 }, "file": { "title": "Attached File", "type": "file", "accept": "image/*" }, "prefecture": { "title": "Prefecture", "type": "select", "items": [ { "title": "Tokyo", "value": "13" }, { "title": "Kanagawa", "value": "14" } ] }, "fruits": { "title": "Fruits", "type": "checkbox", "items": [ { "title": "Apple", "value": "apple" }, { "title": "Banana", "value": "banana" }, { "title": "Grape", "value": "grape" } ] }, "gender": { "title": "Gender", "type": "radio", "items": [ { "title": "Male", "value": "1" }, { "title": "Female", "value": "2" } ] } } ``` ``` -------------------------------- ### Asynchronous Processing - Initial Request (With File) Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/AIアプリAPI仕様.md Example of an initial request for asynchronous processing when file data is included. ```APIDOC #### Initial Request Example 2: With File Files are included in `inputs.files` in the format `{"any_key": {"contents": "...", "filename": "..."}}`. `contents` is a Base64 encoded string. ```bash # Replace with your deployment output URL="YOUR_INITIAL_REQUEST_URL" API_KEY="YOUR_API_KEY" # Base64 encoded file content (e.g., text "hello world") FILE_CONTENTS=$(echo -n "hello world" | base64) # Data to send DATA='''{ "inputs": { "question": "Please summarize the content of this file.", "files": [ { "key": "source_document", "contents": "'${FILE_CONTENTS}'", "filename": "input.txt" } ] } }''' curl -v -X POST \ -H "Content-Type: application/json" \ -H "x-api-key: ${API_KEY}" \ -d "${DATA}" \ "${URL}" ``` -------------------------------- ### Local Development Server Output Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/ローカル開発環境.md This message indicates the local development server has started successfully. Access http://localhost:5173/ in your browser to verify. ```shell ➜ Local: http://localhost:5173/ ➜ Network: use --host to expose ➜ press h + enter to show help ``` -------------------------------- ### Asynchronous Initial Request (With File) Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/AIアプリAPI仕様.md Example of an initial POST request for asynchronous processing, including a file. The file content must be Base64 encoded and placed within the 'inputs.files' array. ```bash # デプロイ時の出力に置き換えてください URL="YOUR_INITIAL_REQUEST_URL" API_KEY="YOUR_API_KEY" # Base64エンコードされたファイルコンテンツ (例: "hello world"というテキスト) FILE_CONTENTS=$(echo -n "hello world" | base64) # 送信するデータ DATA='''{ "inputs": { "question": "このファイルの内容を要約してください。", "files": [ { "key": "source_document", "contents": "'${FILE_CONTENTS}'", "filename": "input.txt" } ] } }''' curl -v -X POST \ -H "Content-Type: application/json" \ -H "x-api-key: ${API_KEY}" \ -d "${DATA}" \ "${URL}" ``` -------------------------------- ### Sent Request Example Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/AIアプリAPI仕様.md Example of the request sent from GenAI Web to the AI application, based on the sample input structure. ```APIDOC ## Sent Request Example When the sample above is defined, GenAI Web sends the following request to the AI application. Please implement the API to retrieve values under `inputs` for processing. ```json { "inputs": { "question": "What is the default value?", "content": "Content\nContent", "step": 35, "files": [ { "key": "key_name", "files": [ { "filename": "file_name", "content": "base64_data" }, { "filename": "file_name", "content": "base64_data" } ] }, { "key": "key_name", "files": [ { "filename": "file_name", "content": "base64_data" }, { "filename": "file_name", "content": "base64_data" } ] } ], "prefecture": 13, "fruits": "apple,banana", "gender": 1 } } ``` ### Notes - Numbers are sent as numbers, not strings, even if enclosed in `""`. - `true` / `false` are sent as booleans, even if enclosed in `""`. - When multiple checkboxes are selected, they are sent as a comma-separated string like `"a,b,c"`. - If a single checkbox is selected, it is sent as a string without a comma, like `"a"`. - Files are sent as Base64 encoded content. - Be aware that validation is performed on the Base64 converted value, even if the file size is less than `max_size`. ``` -------------------------------- ### Verify Node.js Version Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/事前準備.md Check if the installed Node.js version matches the one specified in .node-version or mise.toml. ```bash node -v ``` -------------------------------- ### Asynchronous Initial Request (Text Only) Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/AIアプリAPI仕様.md Example of an initial POST request for asynchronous processing, sending only text-based inputs. Ensure data is wrapped in an 'inputs' key and includes necessary headers. ```bash # デプロイ時の出力に置き換えてください URL="YOUR_INITIAL_REQUEST_URL" # /requests で終わるURL API_KEY="YOUR_API_KEY" # 送信するデータ。必ず "inputs" キーでラップすること。 # この形式は後述のカスタマイズポイントで定義します。 DATA='''{ "inputs": { "question": "日本の歴史について、500文字程度で要約してください。", "max_length": 512 } }''' curl -v -X POST \ -H "Content-Type: application/json" \ -H "x-api-key: ${API_KEY}" \ -d "${DATA}" \ "${URL}" ``` -------------------------------- ### External AI App Sync Implementation (Server-side) Source: https://context7.com/digital-go-jp/genai-web/llms.txt Example of how an external API server would implement synchronous AI app processing. It details the expected request format including inputs and optional files. ```bash # 同期処理の実装例(外部APIサーバー側) # リクエスト形式 curl -X POST https://your-api.example.com/api/summarize \ -H "Content-Type: application/json" \ -H "x-api-key: YOUR_API_KEY" \ -H "x-user-id: stable-user-id" \ -d '{ "inputs": { "document": "議事録のテキスト...", "summary_level": "standard", "files": [ { "key": "attachment", "files": [ { "filename": "document.pdf", "content": "base64エンコードされたデータ" } ] } ] }, "sessionId": "uuid-for-conversation-history" }' # 同期レスポンス # HTTP 200 OK # { "outputs": "## 要約結果\n\nMarkdown形式の出力テキスト..." } ``` -------------------------------- ### Asynchronous Processing - Initial Request (Text Only) Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/AIアプリAPI仕様.md Example of an initial request for asynchronous processing when only text data is involved. ```APIDOC ### Asynchronous Processing #### Initial Request Example 1: Text Only ```bash # Replace with your deployment output URL="YOUR_INITIAL_REQUEST_URL" # URL ending with /requests API_KEY="YOUR_API_KEY" # Data to send. Must be wrapped with the "inputs" key. # This format is defined in the customization points described later. DATA='''{ "inputs": { "question": "Please summarize Japanese history in about 500 characters.", "max_length": 512 } }''' curl -v -X POST \ -H "Content-Type: application/json" \ -H "x-api-key: ${API_KEY}" \ -d "${DATA}" \ "${URL}" ``` -------------------------------- ### External AI App Async Implementation (Server-side) Source: https://context7.com/digital-go-jp/genai-web/llms.txt Example of how an external API server would implement asynchronous AI app processing. It shows the initial accepted response and the structure of status updates. ```bash # 非同期処理の実装例 # 初期レスポンス (HTTP 202 Accepted) # { # "outputs": "処理を開始しました", # "request_id": "req-uuid", # "status": "PENDING", # "status_url": "/status/req-uuid" # } # ステータスエンドポイント (GET /status/{request_id}) # 処理中: { "status": "IN_PROGRESS", "progress": "処理中... 50%" } # 完了時: { # "status": "COMPLETED", # "outputs": "処理結果のテキスト", # "artifacts": [ # { "contents": "base64エンコードされたPDF", "display_name": "report.pdf" } # ] # } ``` -------------------------------- ### Add System Admin via Script Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/システム管理者設定手順.md Use this script to add a user to the SystemAdminGroup. Ensure prerequisites like CloudFormation stack deployment and Cognito user registration are met. jq must be installed. ```bash # parameter.tsのenvキーは `'-dev': devParams,` となっていたらキー値(例では `-dev`)を指定してください ./scripts/add-system-admin.sh <ユーザー名> # 例 ./scripts/add-system-admin.sh -dev user@example.com # 成功した場合、以下のような出力が表示されます。 > 完了: ユーザー 'xxxxxxx@example.com' を SystemAdminGroup に追加しました。 ``` -------------------------------- ### Deploy CDK with Log Sending Enabled Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/ログ設定.md Deploy the CDK project including the `LoggingStack` which is part of `GenerativeAiUseCasesStack`. Use the `--all` flag to deploy all stacks. Ensure you specify the correct environment, for example, `--c env=-prod` for the production environment. ```bash npm ci npm -w packages/cdk run cdk -- deploy --all --require-approval never -c env=-prod ``` -------------------------------- ### Get All AI Applications (ExApps) using ExApp API Source: https://context7.com/digital-go-jp/genai-web/llms.txt Retrieve a list of all available AI applications (ExApps) across the platform. This endpoint is useful for discovering and accessing various AI tools. ```typescript // AIアプリ一覧取得 - GET /exapps const exAppsResponse = await fetch('/api/exapps', { headers: { 'Authorization': `Bearer ${idToken}` } }); ``` -------------------------------- ### Start Audio Transcription API Source: https://context7.com/digital-go-jp/genai-web/llms.txt Initiates audio transcription using AWS Transcribe. Supports speaker separation. Requires audio key and optional speaker label and max speakers parameters. ```typescript // 文字起こし開始 - POST /transcription/start const startTranscriptionRequest = { audioKey: 'path/to/audio.mp3', speakerLabel: true, maxSpeakers: 3 }; const startResponse = await fetch('/api/transcription/start', { method: 'POST', headers: { 'Authorization': `Bearer ${idToken}`, 'Content-Type': 'application/json' }, body: JSON.stringify(startTranscriptionRequest) }); const { jobName } = await startResponse.json(); ``` -------------------------------- ### Get Team's AI Applications (ExApps) using ExApp API Source: https://context7.com/digital-go-jp/genai-web/llms.txt Fetch a list of AI applications (ExApps) specifically associated with a given team. This allows users to see and manage the AI tools available within their team. ```typescript // チーム内AIアプリ一覧 - GET /teams/{teamId}/exapps const teamExAppsResponse = await fetch(`/api/teams/${teamId}/exapps`, { headers: { 'Authorization': `Bearer ${idToken}` } }); ``` -------------------------------- ### Get Chat - GET /chats/{chatId} Source: https://context7.com/digital-go-jp/genai-web/llms.txt Fetches details for a specific chat session using its ID. Requires an Authorization header. ```typescript const getChatResponse = await fetch(`/api/chats/${chatId}`, { headers: { 'Authorization': `Bearer ${idToken}` } }); ``` -------------------------------- ### ローカル環境からデプロイを実行 Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/デプロイ手順.md ローカル環境からデプロイを実行する際に、`-c env=` パラメータを使用して `deploy_envs` で定義した環境を指定します。これにより、デプロイ先の環境を切り替えることができます。 ```bash npm -w packages/cdk run cdk -- deploy --all --require-approval never -c env=-selfHostingDev ``` -------------------------------- ### Status Check (Polling) Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/AIアプリAPI仕様.md Example of how to poll for the status of an asynchronous request using the 'request_id' obtained from the initial response. ```bash # 上記で受け取った request_id を使って、処理のステータスを問い合わせます。 # URL と API_KEY は適宜置き換えてください。 REQUEST_ID="a1b2c3d4-e5f6-7890-1234-567890abcdef" URL="YOUR_STATUS_CHECK_URL" API_KEY="YOUR_API_KEY" curl -v -X GET \ -H "x-api-key: ${API_KEY}" \ "${URL}/${REQUEST_ID}" ``` -------------------------------- ### List Chats - GET /chats Source: https://context7.com/digital-go-jp/genai-web/llms.txt Retrieves a list of existing chat sessions. Supports pagination using exclusiveStartKey. ```typescript const listChatsResponse = await fetch('/api/chats?exclusiveStartKey=null', { headers: { 'Authorization': `Bearer ${idToken}` } }); // Response: { "data": [{ "chatId": "...", "title": "...", "updatedDate": "..." }], "lastEvaluatedKey": "..." } ``` -------------------------------- ### テンプレートファイルをコピー Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/デプロイ手順.md 環境固有のパラメータ設定ファイルを作成するために、テンプレートファイルをコピーします。`cd` コマンドでディレクトリに移動してから `cp` コマンドを実行してください。 ```bash cd packages/cdk/env-parameters cp self-hosting-template.ts self-hosting-dev.ts ``` -------------------------------- ### List Messages - GET /chats/{chatId}/messages Source: https://context7.com/digital-go-jp/genai-web/llms.txt Retrieves all messages within a specific chat session using its ID. Requires an Authorization header. ```typescript const messagesResponse = await fetch(`/api/chats/${chatId}/messages`, { headers: { 'Authorization': `Bearer ${idToken}` } }); // Response: { "messages": [{ "messageId": "...", "role": "...", "content": "...", "createdDate": "..." }] } ``` -------------------------------- ### Get AI App History Source: https://context7.com/digital-go-jp/genai-web/llms.txt Retrieve the execution history for a specific AI application within a team. This endpoint requires the team ID and application ID. ```typescript // 実行履歴取得 - GET /exapps/history const historyResponse = await fetch(`/api/teams/${teamId}/exapps/${exAppId}/history`, { headers: { 'Authorization': `Bearer ${idToken}` } }); ``` -------------------------------- ### Bootstrap AWS CDK Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/事前準備.md Perform the initial AWS CDK bootstrap for a new AWS account and region combination before deploying. ```bash npm -w packages/cdk run cdk -- bootstrap ``` -------------------------------- ### GitHub Actions 用ワークフローファイルをコピー Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/デプロイ手順.md GitHub Actions を使用してデプロイする場合、デプロイ用ワークフローファイルのサンプルをコピーして、環境名に合わせてリネームします。その後、ワークフロー内のコメントに従って設定を行ってください。 ```bash cp .github/genai-deploy.yaml.example .github/workflows/genai-deploy-{環境名}.yaml ``` -------------------------------- ### Get Signed URL for File Download Source: https://context7.com/digital-go-jp/genai-web/llms.txt Request a pre-signed URL to download a file from S3 using its key. The file key is typically obtained after a successful upload. ```typescript // ダウンロード用署名付きURL取得 - GET /file/url const downloadUrlResponse = await fetch( `/api/file/url?bucketName=bucket&filePrefix=${encodeURIComponent(fileKey)}`, { headers: { 'Authorization': `Bearer ${idToken}` } } ); const downloadUrl = await downloadUrlResponse.text(); ``` -------------------------------- ### Get Signed URL for File Upload Source: https://context7.com/digital-go-jp/genai-web/llms.txt Request a pre-signed URL from the API to upload a file to S3. The response provides the upload URL and a file key for later reference. ```typescript // アップロード用署名付きURL取得 - POST /file/url const uploadUrlResponse = await fetch('/api/file/url', { method: 'POST', headers: { 'Authorization': `Bearer ${idToken}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ filename: 'document.pdf', mediaFormat: 'application/pdf' }) }); const { url: uploadUrl, key: fileKey } = await uploadUrlResponse.json(); ``` -------------------------------- ### Get Team Members List using Team Management API Source: https://context7.com/digital-go-jp/genai-web/llms.txt Retrieve a list of all users associated with a specific team. This endpoint is useful for auditing and managing team membership. ```typescript // チームメンバー一覧 - GET /teams/{teamId}/users const usersResponse = await fetch(`/api/teams/${teamId}/users`, { headers: { 'Authorization': `Bearer ${idToken}` } }); ``` -------------------------------- ### パラメータ設定ファイルをインポート Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/デプロイ手順.md デプロイ環境を `parameter.ts` の `deploy_envs` オブジェクトに追加します。これにより、異なる環境へのデプロイが可能になります。 ```typescript import { selfHostingDevParams } from "./env-parameters/self-hosting-dev"; const deploy_envs: Record> = { "-selfHostingDev": selfHostingDevParams, // 他の環境も追加可能 }; ``` -------------------------------- ### GET /status/{requestId} Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/AIアプリAPI仕様.md Retrieves the status of a processing request. The URL should be constructed by appending the request ID to a base URL that ends with '/status/'. An API key is required for authentication. ```APIDOC ## GET /status/{requestId} ### Description Retrieves the status of a processing request using its unique request ID. ### Method GET ### Endpoint `/status/{requestId}` ### Parameters #### Path Parameters - **requestId** (string) - Required - The unique identifier for the request. #### Headers - **x-api-key** (string) - Required - Your API key for authentication. ### Request Example ```bash curl -X GET \ -H "Content-Type: application/json" \ -H "x-api-key: YOUR_API_KEY" \ "YOUR_STATUS_CHECK_URL_BASE/status/a1b2c3d4-e5f6-7890-1234-567890abcdef" ``` ### Response #### Success Response (200) - **request_id** (string) - The unique identifier for the request. - **status** (string) - The current status of the request (e.g., PENDING, IN_PROGRESS, COMPLETED, ERROR). - **created_at** (string) - Timestamp when the request was created. - **updated_at** (string) - Timestamp when the request was last updated. - **progress** (string) - A human-readable description of the current progress. - **outputs** (string) - Optional. Text output of the processing, present when status is COMPLETED. - **artifacts** (array) - Optional. File outputs of the processing, present when status is COMPLETED. Each artifact contains `contents` (Base64 encoded) and `display_name`. - **error** (object) - Optional. Contains error details (`message`, `details`) when status is ERROR. #### Response Example (Processing) ```json { "created_at": "2025-08-06T10:00:00.123Z", "progress": "処理中... ステップ 3/5", "request_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "status": "IN_PROGRESS", "updated_at": "2025-08-06T10:02:30.456Z" } ``` #### Response Example (Completed) ```json { "artifacts": [ { "contents": "JVBERi0xLjAKMSAwIG9iago8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAwIFI+...", "display_name": "dummy-report.pdf" } ], "created_at": "2025-08-06T10:00:00.123Z", "outputs": "This is a dummy output for question: '日本の歴史について、500文字程度で要約してください。'", "progress": "処理が完了しました。結果を保存しています...", "request_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "status": "COMPLETED", "updated_at": "2025-08-06T10:05:00.789Z" } ``` #### Response Example (Error) ```json { "created_at": "2025-08-06T10:00:00.123Z", "error": { "details": "Required resource not found.", "message": "An error occurred during processing." }, "request_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "status": "ERROR", "updated_at": "2025-08-06T10:03:00.500Z" } ``` ``` -------------------------------- ### Self-Hosting Production Deployment Parameters Source: https://context7.com/digital-go-jp/genai-web/llms.txt Configuration for deploying infrastructure using AWS CDK for a self-hosted production environment. Includes settings for app environment, logging, authentication, security, custom domains, AI models, and monitoring. ```typescript // packages/cdk/env-parameters/self-hosting-prod.ts import { StackInput } from '../lib/stack-input'; export const selfHostingProdParams: Partial = { // 基本設定 appEnv: 'prod', logLevel: 'INFO', // 認証設定 selfSignUpEnabled: false, samlAuthEnabled: true, samlCognitoDomainName: 'genai.auth.ap-northeast-1.amazoncognito.com', samlCognitoFederatedIdentityProviderName: 'EntraID', // セキュリティ設定 allowedIpV4AddressRanges: ['203.0.113.0/24', '198.51.100.0/24'], // カスタムドメイン hostName: 'genai', domainName: 'example.go.jp', hostedZoneId: 'Z1234567890ABC', certificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/xxx', // モデル設定 modelRegion: 'ap-northeast-1', modelIds: [ 'jp.anthropic.claude-sonnet-4-5-20250929-v1:0', 'jp.anthropic.claude-haiku-4-5-20251001-v1:0', 'amazon.nova-pro-v1:0', 'amazon.nova-lite-v1:0' ], imageGenerationModelIds: ['amazon.nova-canvas-v1:0'], // 監視設定 monitoring: true, slack: { enabled: true, workspaceId: 'T01234567', channelId: 'C01234567' } }; // packages/cdk/parameter.ts への登録 import { selfHostingProdParams } from './env-parameters/self-hosting-prod'; const deploy_envs: Record> = { '-prod': selfHostingProdParams, }; ``` -------------------------------- ### AWSアクセスキー設定 Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/AIアプリ登録手順書.md AWS CLI コマンドを実行する前に、`AWS_ACCESS_KEY_ID`、`AWS_SECRET_ACCESS_KEY`、`AWS_SESSION_TOKEN` の環境変数を設定します。これらの認証情報は、API キーを取得するために必要です。 ```bash export AWS_ACCESS_KEY_ID ="" export AWS_SECRET_ACCESS_KEY ="" export AWS_SESSION_TOKEN ="" ``` -------------------------------- ### System Context API Source: https://context7.com/digital-go-jp/genai-web/llms.txt API for managing custom system prompts, allowing reuse of AI behavior settings. ```APIDOC ## POST /systemcontexts ### Description Creates a new system context. ### Method POST ### Endpoint /api/systemcontexts ### Request Body - **systemContext** (object) - Required - The system context object. - **systemContextId** (string) - Required - A unique identifier for the system context. - **systemContext** (string) - Required - The content of the system prompt. - **systemContextTitle** (string) - Required - The title of the system context. ### Request Example ```json { "systemContext": { "systemContextId": "some-uuid", "systemContext": "You are an AI assistant that helps create administrative documents. Please use polite and accurate Japanese suitable for official documents.", "systemContextTitle": "Administrative Document Assistant" } } ``` ## GET /systemcontexts ### Description Retrieves a list of all system contexts. ### Method GET ### Endpoint /api/systemcontexts ### Response #### Success Response (200) - Returns a list of system context objects. ## PUT /systemcontexts/{systemContextId}/title ### Description Updates the title of a specific system context. ### Method PUT ### Endpoint /api/systemcontexts/{systemContextId}/title ### Parameters #### Path Parameters - **systemContextId** (string) - Required - The ID of the system context to update. ### Request Body - **title** (string) - Required - The new title for the system context. ### Request Example ```json { "title": "New Title" } ``` ## DELETE /systemcontexts/{systemContextId} ### Description Deletes a specific system context. ### Method DELETE ### Endpoint /api/systemcontexts/{systemContextId} ### Parameters #### Path Parameters - **systemContextId** (string) - Required - The ID of the system context to delete. ``` -------------------------------- ### Create System Context API Source: https://context7.com/digital-go-jp/genai-web/llms.txt Saves and manages custom system prompts for AI behavior settings. Requires system context ID, the prompt itself, and a title. ```typescript // システムコンテキスト作成 - POST /systemcontexts const createContextRequest = { systemContext: { systemContextId: crypto.randomUUID(), systemContext: 'あなたは行政文書の作成を支援するAIアシスタントです。公式文書にふさわしい丁寧で正確な日本語を使用してください。', systemContextTitle: '行政文書作成アシスタント' } }; await fetch('/api/systemcontexts', { method: 'POST', headers: { 'Authorization': `Bearer ${idToken}`, 'Content-Type': 'application/json' }, body: JSON.stringify(createContextRequest) }); ``` -------------------------------- ### Create AI Application (ExApp) using ExApp API Source: https://context7.com/digital-go-jp/genai-web/llms.txt Register an external AI application (ExApp) within a team. This involves defining its name, endpoint, description, API key, and UI component structure using a JSON schema. The 'placeholder' field dynamically generates forms. ```typescript // AIアプリ作成 - POST /teams/{teamId}/exapps const createExAppRequest = { exAppName: '議事録要約アプリ', endpoint: 'https://api.example.com/summarize', description: '会議の議事録を自動的に要約するAIアプリです。', howToUse: '1. 議事録テキストを入力\n2. 要約レベルを選択\n3. 実行ボタンをクリック', apiKey: 'your-api-key-here', copyable: true, status: 'published', placeholder: JSON.stringify({ document: { type: 'textarea', title: '議事録', desc: '要約したい議事録のテキストを入力してください', required: true, min_length: 100, max_length: 50000 }, summary_level: { type: 'select', title: '要約レベル', items: [ { title: '簡潔(1段落)', value: 'brief' }, { title: '標準(3段落)', value: 'standard' }, { title: '詳細(5段落)', value: 'detailed' } ], default_value: 'standard' }, include_action_items: { type: 'checkbox', title: '抽出項目', items: [ { title: 'アクションアイテム', value: 'actions' }, { title: '決定事項', value: 'decisions' }, { title: '次回予定', value: 'next_steps' } ] }, attachment: { type: 'file', title: '添付ファイル', accept: 'application/pdf,.docx', max_size: '10MB', multiple: true } }) }; const exAppResponse = await fetch(`/api/teams/${teamId}/exapps`, { method: 'POST', headers: { 'Authorization': `Bearer ${idToken}`, 'Content-Type': 'application/json' }, body: JSON.stringify(createExAppRequest) }); // Response: { "teamId": "...", "exAppId": "uuid", "exAppName": "議事録要約アプリ", ... } ``` -------------------------------- ### Create Chat - POST /chats Source: https://context7.com/digital-go-jp/genai-web/llms.txt Initiates a new chat session. Requires an Authorization header with an ID token. ```typescript const createChatResponse = await fetch('/api/chats', { method: 'POST', headers: { 'Authorization': `Bearer ${idToken}`, 'Content-Type': 'application/json' } }); // Response: { "chat": { "chatId": "uuid", "title": "", "usecase": "chat", "updatedDate": "2024-01-01T00:00:00Z" } } ``` -------------------------------- ### Sample API Request Payload Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/AIアプリAPI仕様.md Example of the JSON payload sent to the AI application based on the defined inputs. Note how different data types are represented, including comma-separated strings for checkboxes and Base64 for files. ```json { "inputs": { "question": "デフォルト値とは何ですか?", "content": "コンテンツコンテンツ\nコンテンツ", "step": 35, "files": [ { "key": "key名", "files": [ { "filename": "ファイル名", "content": "base64データ" }, { "filename": "ファイル名", "content": "base64データ" } ] }, { "key": "key名", "files": [ { "filename": "ファイル名", "content": "base64データ" }, { "filename": "ファイル名", "content": "base64データ" } ] } ], "prefecture": 13, "fruits": "apple,banana", "gender": 1 } } ``` -------------------------------- ### List System Contexts API Source: https://context7.com/digital-go-jp/genai-web/llms.txt Retrieves a list of all saved system contexts. Requires authorization header. ```typescript // システムコンテキスト一覧取得 - GET /systemcontexts const contextsResponse = await fetch('/api/systemcontexts', { headers: { 'Authorization': `Bearer ${idToken}` } }); ``` -------------------------------- ### Get Teams List using Team Management API Source: https://context7.com/digital-go-jp/genai-web/llms.txt Retrieve a list of teams, optionally filtering by name. This endpoint supports pagination using 'limit' and 'lastEvaluatedKey' parameters. Useful for browsing existing teams. ```typescript // チーム一覧取得 - GET /teams const teamsResponse = await fetch('/api/teams?limit=20&name=政策', { headers: { 'Authorization': `Bearer ${idToken}` } }); // Response: { "teams": [...], "lastEvaluatedKey": "..." } ``` -------------------------------- ### Add Log Sending Configuration to Parameter File Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/ログ設定.md Add these settings to your environment's parameter file (e.g., `env-parameters/self-hosting-prod.ts`) to configure the log sending feature. Ensure the `destination.accountId` and `destination.endpointUrl` match your receiving API endpoint details. The `logAccumulationBucketExpirationDays` sets the temporary storage duration, while `DailyExportEventHourUTC` and `TransferS3LogsHourUTC` define the export and transfer times, respectively. The transfer time must be after the export time. ```typescript export const commonProdParams: Partial = { // ... 既存の設定はそのまま ... // ▼ ログ送信機能の設定(ここを追加) destination: { accountId: "123456789012", // 手順 1. でメモした受信側アカウント ID endpointUrl: "https://xxx.execute-api.ap-northeast-1.amazonaws.com/prod/", // 手順 1. でメモした API エンドポイント URL }, logAccumulationBucketExpirationDays: 364, // 自アカウント S3 の一時保存期間(日数) DailyExportEventHourUTC: "17", // DynamoDB エクスポート時刻(UTC)= JST 02:00 TransferS3LogsHourUTC: "18", // 受信側への送信時刻(UTC)= JST 03:00 }; ``` -------------------------------- ### Sample API Input Definition Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/AIアプリAPI仕様.md Defines various input fields for the AI application, including text, textarea, number, file, select, checkbox, and radio types. Each field has properties like title, description, type, and requirements. ```json { "question": { "title": "入力", "desc": "質問したい内容を入力してください。", "type": "text", "required": true, "default_value": "デフォルト値" }, "content": { "title": "コンテンツ", "desc": "マークダウンでコンテンツを入力してください。", "type": "textarea" }, "step": { "title": "number inputの例", "type": "number", "required": true, "min": 10, "max": 1000, "default_value": 20 }, "file": { "title": "添付ファイル", "type": "file", "accept": "image/*" }, "prefecture": { "title": "都道府県", "type": "select", "items": [ { "title": "東京都", "value": "13" }, { "title": "神奈川県", "value": "14" } ] }, "fruits": { "title": "フルーツ", "type": "checkbox", "items": [ { "title": "りんご", "value": "apple" }, { "title": "ばなな", "value": "banana" }, { "title": "ぶどう", "value": "grape" } ] }, "gender": { "title": "性別", "type": "radio", "items": [ { "title": "男性", "value": "1" }, { "title": "女性", "value": "2" } ] } } ``` -------------------------------- ### Generate Image Variation using Amazon Titan Source: https://context7.com/digital-go-jp/genai-web/llms.txt Create variations of an existing image using the Amazon Titan Image Generator. Provide the base64 encoded initial image and a text prompt to guide the variation. The output will be a new image based on the input. ```typescript // 画像バリエーション生成 const variationRequest = { model: { type: 'bedrock', modelId: 'amazon.titan-image-generator-v2:0' }, params: { taskType: 'IMAGE_VARIATION', textPrompt: [{ text: '同じ構図で秋の風景に変更', weight: 1.0 }], initImage: 'base64エンコードされた元画像', cfgScale: 7.0, height: 1024, width: 1024 } }; ``` -------------------------------- ### AWS CDK Deployment Commands Source: https://context7.com/digital-go-jp/genai-web/llms.txt Commands for deploying, deploying specific stacks, or destroying infrastructure using AWS CDK. Uses environment parameters for configuration. ```bash # デプロイコマンド npm -w packages/cdk run cdk -- deploy --all --require-approval never -c env=-prod # 特定のスタックのみデプロイ npm -w packages/cdk run cdk -- deploy GenAIWebStack-prod --require-approval never -c env=-prod # スタック削除 npm -w packages/cdk run cdk destroy -- --all -c env=-prod ``` -------------------------------- ### Create Common App Team Script Source: https://github.com/digital-go-jp/genai-web/blob/main/docs/共通アプリチームの登録.md Execute this shell script to create a common app team. Ensure you provide the correct environment key from your parameter.ts file. ```bash # parameter.tsのenvキーは `'-dev': devParams,` となっていたらキー値(例では `-dev`)を指定してください ./scripts/create-common-app-team.sh # 例 # ./scripts/create-common-app-team.sh -dev ```