Skip to content

Commit

Permalink
Merge pull request #73 from aws-samples/feature/i18n-zh-ko
Browse files Browse the repository at this point in the history
Feature/i18n zh ko
  • Loading branch information
wadabee authored Oct 25, 2023
2 parents b9d3a67 + fd9257e commit 86d1263
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 136 deletions.
126 changes: 51 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,44 @@

![](https://github.com/aws-samples/bedrock-claude-chat/actions/workflows/test.yml/badge.svg)

日本語は[こちら](./docs/README_ja.md)

> **Warning**
> The current version (`v0.2.x`) has no compatibility with ex version (`v0.1.0`) due to the change of the conversation schema. Please note that conversations stored in DynamoDB with ex version cannot be rendered.
This repository is a sample chatbot using the Anthropic company's LLM [Claude 2](https://www.anthropic.com/index/claude-2), one of the foundational models provided by [Amazon Bedrock](https://aws.amazon.com/bedrock/) for generative AI.

![](./docs/imgs/demo_en.png)
![](./docs/imgs/demo2.gif)
![](./docs/imgs/demo1.gif)

## 📚 Supported Languages

- English 💬
- 日本語 💬 (ドキュメントは[こちら](./docs/README_ja.md))
- 한국어 💬
- 中文 💬

## 🚀 Super-easy Deployment

- Open [Bedrock Model access](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/modelaccess) > `Edit` > Check `Claude` and `Save changes`
- Open [CloudShell](https://console.aws.amazon.com/cloudshell/home)
- Run deployment via following commands

```sh
git clone https://github.com/aws-samples/bedrock-claude-chat.git
cd bedrock-claude-chat
chmod +x bin.sh
./bin.sh
```

- After about 20 minutes, you will get the following output, which you can access from your browser

```
Frontend URL: https://xxxxxxxxx.cloudfront.net
```

![](./docs/imgs/signin.png)

The sign-up screen will appear as shown above, where you can register your email and log in.

If want to customize configuration such as IP address restriction, refer [Deploy using CDK](#deploy-using-cdk) section.

## Architecture

Expand All @@ -37,45 +66,14 @@ It's an architecture built on AWS managed services, eliminating the need for inf
- [x] Streaming Response
- [x] IP address restriction
- [x] Edit message & re-send
- [x] I18n (English / Japanese)
- [x] I18n
- [ ] Save and re-use prompt template

## Deployment
## Deploy using CDK

### 🚀 Easy Deployment
Super-easy Deployment uses [AWS CodeBuild](https://aws.amazon.com/codebuild/) to perform deployment by CDK internally. This section describes the procedure for deploying directly with CDK.

> Note: Bedrock currently does NOT support all regions. Following procedure will deploy Bedrock resource to `us-east-1` (Other resources will be deployed on the region where the CloudShell run). If you need to change the Bedrock region, follow the instructions later in this chapter to deploy using CDK directly.
- Open [CloudShell](https://console.aws.amazon.com/cloudshell/home)
- Clone this repository

```sh
git clone https://github.com/aws-samples/bedrock-claude-chat.git
```

- Run deployment via following commands

```sh
cd bedrock-claude-chat
chmod +x bin.sh
./bin.sh
```

- After about 10 minutes, you will get the following output, which you can access from your browser

```
Frontend URL: https://xxxxxxxxx.cloudfront.net
```

![](./docs/imgs/signin.png)

The sign-up screen will appear as shown above, where you can register your email and log in.

### Deploy using CDK

Easy Deployment uses [AWS CodeBuild](https://aws.amazon.com/codebuild/) to perform deployment by CDK internally. This section describes the procedure for deploying directly with CDK.

- Please have UNIX commands and a Node.js runtime environment. If not, you can also use [Cloud9](https://github.com/aws-samples/cloud9-setup-for-prototyping)
- Please have UNIX and a Node.js runtime environment. If not, you can also use [Cloud9](https://github.com/aws-samples/cloud9-setup-for-prototyping)
- Clone this repository

```
Expand All @@ -102,9 +100,9 @@ npm i -g aws-cdk
cdk bootstrap aws://<account id>/us-east-1
```

- If necessary, edit the following entries in [cdk.json](. /cdk/cdk.json) if necessary.
- If necessary, edit the following entries in [cdk.json](./cdk/cdk.json) if necessary.

- `bedrockRegion`: Region where Bedrock is available.
- `bedrockRegion`: Region where Bedrock is available. **NOTE: Bedrock does NOT support all regions for now.**
- `allowedIpV4AddressRanges`, `allowedIpV6AddressRanges`: Allowed IP Address range.

- Deploy this sample project
Expand Down Expand Up @@ -143,52 +141,26 @@ GENERATION_CONFIG = {
}
```

### Delete Resources
### Remove resources

If you are using the CLI and CDK, run `cdk destroy`. Otherwise, access [CloudFormation](https://console.aws.amazon.com/cloudformation/home) and manually delete the `BedrockChatStack` and `FrontendWafStack` stacks. `FrontendWafStack` is in the us-east-1 region.
If using cli and CDK, please `cdk destroy`. If not, access to [CloudFormation](https://console.aws.amazon.com/cloudformation/home) then delete `BedrockChatStack` and `FrontendWafStack` manually. Please note that `FrontendWafStack` is on `us-east-1` region.

### Language Settings

This asset automatically detects the language using [i18next-browser-languageDetector](https://github.com/i18next/i18next-browser-languageDetector).You can switch languages from the application menu. Alternatively, you can use Query String to set the language as shown below.

> `https://example.com?lng=ja`
### Local Frontend Development

In this sample, you can locally modify and launch the frontend using AWS resources (`API Gateway`, `Cognito`, etc.) that have been deployed with `cdk deploy`.

1. Refer to [Deploy using CDK](#deploy-using-cdk) for deploying on the AWS environment.
2. Copy the `frontend/.env.template` and save it as `frontend/.env.local`.
3. Fill in the contents of `.env.local` based on the output results of `cdk deploy` (such as `BedrockChatStack.AuthUserPoolClientIdXXXXX`).
4. Execute the following command:

```zsh
cd frontend && npm run dev
```

### Using Streaming

Currently, the environment variable `VITE_APP_USE_STREAMING` is specified on the frontend side. It's recommended to set it to `false` when running the backend locally and `true` when operating on AWS.
When streaming is enabled, text is generated in real-time due to the streaming of content generation results.
### Local Development

### Local development using docker compose
See [LOCAL DEVELOPMENT](./docs/LOCAL_DEVELOPMENT.md).

[docker-compose.yml](./docker-compose.yml) allows you to run and develop frontend/backend APIs/DynamoDB Local in your local environment.
### Contribution

```bash
# Build containers
docker compose build
Thank you for considering contribution on this repository! We welcome for bug fixes, language translation, feature enhancements, and other improvements. Please see following:

# Launch containers
docker compose up

# Stop containers
docker compose down
```

### Remove resources

If using cli and CDK, please `cdk destroy`. If not, access to [CloudFormation](https://console.aws.amazon.com/cloudformation/home) then delete `BedrockChatStack` and `FrontendWafStack` manually. Please note that `FrontendWafStack` is on `us-east-1` region.
- [Local Development](./docs/LOCAL_DEVELOPMENT.md)
- [CONTRIBUTING](./CONTRIBUTING.md)

### RAG using Kendra

Expand All @@ -202,3 +174,7 @@ In this sample, we have not implemented RAG using Kendra. This is because when i

- [Takehiro Suzuki](https://github.com/statefb)
- [Yusuke Wada](https://github.com/wadabee)

## License

This library is licensed under the MIT-0 License. See the LICENSE file.
7 changes: 6 additions & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

Written in Python with [FastAPI](https://fastapi.tiangolo.com/).

## Unit test on local
- To get started, we need to deploy resources to create DynamoDB / Bedrock resource. To deploy, please see [Deploy using CDK](../README.md#deploy-using-cdk).
- Create virtual environment on your local machine

```
cd backend
Expand All @@ -11,13 +12,17 @@ source .venv/bin/activate
pip install -r ./requirements.txt
```

- Configure environment variables

```
export TABLE_NAME=BedrockChatStack-DatabaseConversationTablexxxx
export ACCOUNT=yyyy
export REGION=ap-northeast-1
export BEDROCK_REGION=us-east-1
```

- Run unit test

```
python tests/test_conversation.py TestConversationRepository
python tests/test_bedrock.py
Expand Down
38 changes: 38 additions & 0 deletions docs/LOCAL_DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Local development

## Backend Development

See [backend/README](../backend/README.md).

## Frontend Development

In this sample, you can locally modify and launch the frontend using AWS resources (`API Gateway`, `Cognito`, etc.) that have been deployed with `cdk deploy`.

1. Refer to [Deploy using CDK](../README.md#deploy-using-cdk) for deploying on the AWS environment.
2. Copy the `frontend/.env.template` and save it as `frontend/.env.local`.
3. Fill in the contents of `.env.local` based on the output results of `cdk deploy` (such as `BedrockChatStack.AuthUserPoolClientIdXXXXX`).
4. Execute the following command:

```zsh
cd frontend && npm ci && npm run dev
```

### Using Streaming

Currently, the environment variable `VITE_APP_USE_STREAMING` is specified on the frontend side. It's recommended to set it to `false` when running the backend locally and `true` when operating on AWS.
When streaming is enabled, text is generated in real-time due to the streaming of content generation results.

## Using docker compose

If you prefer to handle all of resources as Docker, [docker-compose.yml](./docker-compose.yml) allows you to run and develop frontend / backend APIs / DynamoDB Local in your local environment.

```bash
# Build containers
docker compose build

# Launch containers
docker compose up

# Stop containers
docker compose down
```
38 changes: 38 additions & 0 deletions docs/LOCAL_DEVELOPMENT_ja.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# ローカル環境での開発

## バックエンド

[backend/README](../backend/README.md)を参照下さい。

## フロントエンド

現在このサンプルでは、`cdk deploy` された AWS リソース(API Gateway、Cognito など)を使用してローカルでフロントを立ち上げながら改変作業を加えることができます。

1. [Deploy using CDK](./README_ja.md#deploy-using-cdk) を参考に AWS 環境上にデプロイを行う
2. `frontend/.env.template` 複製し `frontend/.env.local` という名前で保存する。
3. `.env.local` の中身を `cdk deploy` の出力結果(`BedrockChatStack.AuthUserPoolClientIdXXXXX` など)を見ながら穴埋めしていく
4. 下記コマンドを実行する

```zsh
cd frontend && npm ci && npm run dev
```

### ストリーミングの利用

現在、環境変数として `VITE_APP_USE_STREAMING` というのをフロントエンド側で指定しています。バックエンドをローカルで動かす場合は `false` に指定してただき、AWS で動かす場合は `true` にすることを推奨します。
Streaming を有効化すると文章生成結果がストリーミングされるためリアルタイムで文字列が生成されていきます。

### コンテナを利用したローカルでの開発について

[docker-compose.yml](../docker-compose.yml) を利用することで、フロントエンド / バックエンド API / DynamoDB Local をローカル環境で動かし開発を行うことができます。

```bash
# コンテナのビルド
docker compose build

# コンテナの起動
docker compose up

# コンテナの停止
docker compose down
```
Loading

0 comments on commit 86d1263

Please sign in to comment.