aws-samples / bedrock-claude-chat
- воскресенье, 5 мая 2024 г. в 00:00:07
AWS-native chatbot using Bedrock + Claude
Tip
🔔Claude3 Opus supported. As of 04/17/2024, Bedrock only supports the us-west-2
region. In this repository, Bedrock uses the us-east-1
region by default. Therefore, if you plan to use it, please change the value of bedrockRegion
before deployment. For more details, please refer here.
Warning
The current version (v0.4.x
) has no compatibility with the previous version (~v0.3.0
) due to changes in the DynamoDB table schema. Please note that the UPDATE (i.e. cdk deploy
) FROM PREVIOUS VERSION TO v0.4.x
WILL DESTROY ALL OF THE EXISTING CONVERSATIONS.
This repository is a sample chatbot using the Anthropic company's LLM Claude, one of the foundational models provided by Amazon Bedrock for generative AI.
Not only text but also images are available with Anthropic's Claude 3. Currently we support Haiku
, Sonnet
and Opus
.
Add your own instruction and give external knowledge as URL or files (a.k.a RAG). The bot can be shared among application users. The customized bot also can be published as stand-alone API (See the detail).
Analyze usage for each user / bot on administrator dashboard. detail
Manage model access
> Check Anthropic / Claude 3 Haiku
, Anthropic / Claude 3 Sonnet
and Cohere / Embed Multilingual
then Save changes
.git clone https://github.com/aws-samples/bedrock-claude-chat.git
cd bedrock-claude-chat
chmod +x bin.sh
./bin.sh
Frontend URL: https://xxxxxxxxx.cloudfront.net
The sign-up screen will appear as shown above, where you can register your email and log in.
Important
This deployment method allows anyone with the URL to sign up. For production use, we strongly recommend adding IP address restrictions or disabling self-signup to mitigate security risks. To set up, Deploy using CDK for IP address restrictions or Disable self sign up.
It's an architecture built on AWS managed services, eliminating the need for infrastructure management. Utilizing Amazon Bedrock, there's no need to communicate with APIs outside of AWS. This enables deploying scalable, reliable, and secure applications.
Super-easy Deployment uses AWS CodeBuild to perform deployment by CDK internally. This section describes the procedure for deploying directly with CDK.
Important
If there is insufficient storage space in the local environment during deployment, CDK bootstrapping may result in an error. If you are running in Cloud9 etc., we recommend expanding the volume size of the instance before deploying.
git clone https://github.com/aws-samples/bedrock-claude-chat
cd bedrock-claude-chat
cd cdk
npm ci
npm i -g aws-cdk
<account id>
.cdk bootstrap aws://<account id>/us-east-1
If necessary, edit the following entries in cdk.json if necessary.
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
cdk deploy --require-approval never --all
BedrockChatStack.FrontendURL
, so please access it from your browser. ✅ BedrockChatStack
✨ Deployment time: 78.57s
Outputs:
BedrockChatStack.AuthUserPoolClientIdXXXXX = xxxxxxx
BedrockChatStack.AuthUserPoolIdXXXXXX = ap-northeast-1_XXXX
BedrockChatStack.BackendApiBackendApiUrlXXXXX = https://xxxxx.execute-api.ap-northeast-1.amazonaws.com
BedrockChatStack.FrontendURL = https://xxxxx.cloudfront.net
Update enableMistral
to true
in cdk.json, and run cdk deploy
.
...
"enableMistral": true,
Important
This project focus on Anthropic Claude models, the Mistral models are limited supported. For example, prompt examples are based on Claude models. This is a Mistral-only option, once you toggled to enable Mistral models, you can only use Mistral models for all the chat features, NOT both Claude and Mistral models.
Edit config.py and run cdk deploy
.
# See: https://docs.anthropic.com/claude/reference/complete_post
GENERATION_CONFIG = {
"max_tokens": 2000,
"top_k": 250,
"top_p": 0.999,
"temperature": 0.6,
"stop_sequences": ["Human: ", "Assistant: "],
}
If using cli and CDK, please cdk destroy
. If not, access CloudFormation and then delete BedrockChatStack
and FrontendWafStack
manually. Please note that FrontendWafStack
is in us-east-1
region.
By setting cdk.json in the following CRON format, you can stop and restart Aurora Serverless resources created by the VectorStore construct. Applying this setting can reduce operating costs. By default, Aurora Serverless is always running. Note that it will be executed in UTC time.
...
"rdbSchedules": {
"stop": {
"minute": "50",
"hour": "10",
"day": "*",
"month": "*",
"year": "*"
},
"start": {
"minute": "40",
"hour": "2",
"day": "*",
"month": "*",
"year": "*"
}
}
This asset automatically detects the language using 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
This sample has self sign up enabled by default. To disable self sign up, open auth.ts and switch selfSignUpEnabled
as false
, then re-deploy.
const userPool = new UserPool(this, "UserPool", {
passwordPolicy: {
requireUppercase: true,
requireSymbols: true,
requireDigits: true,
minLength: 8,
},
// Set to false
selfSignUpEnabled: false,
signInAliases: {
username: false,
email: true,
},
});
By default, this sample does not restrict the domains for sign-up email addresses. To allow sign-ups only from specific domains, open cdk.json
and specify the domains as a list in allowedSignUpEmailDomains
.
"allowedSignUpEmailDomains": ["example.com"],
This sample supports external identity provider. Currently we support Google and custom OIDC provider.
See LOCAL DEVELOPMENT.
Thank you for considering contributing to this repository! We welcome bug fixes, language translations (i18n), feature enhancements, and other improvements.
For feature enhancements and other improvements, before creating a Pull Request, we would greatly appreciate it if you could create a Feature Request Issue to discuss the implementation approach and details. For bug fixes and language translations (i18n), proceed with creating a Pull Request directly.
Please also take a look at the following guidelines before contributing:
See here.
This library is licensed under the MIT-0 License. See the LICENSE file.