hyeonsangjeon / bedrock-claude-chat

AWS-native chatbot using Bedrock + Claude

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bedrock Claude Chat

Tip

πŸ””API publication / Admin dashboard feature released. See release for the detail.

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.

Basic Conversation

Not only text but also images are available with Anthropic's Claude 3. Currently we support Haiku and Sonnet.

Bot Personalization

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).

Administrator dashboard

Analyze usage for each user / bot on administrator dashboard. detail

πŸ“š Supported Languages

  • English πŸ’¬
  • ζ—₯本θͺž πŸ’¬ (ドキγƒ₯γƒ‘γƒ³γƒˆγ―γ“γ‘γ‚‰)
  • ν•œκ΅­μ–΄ πŸ’¬
  • δΈ­ζ–‡ πŸ’¬
  • FranΓ§ais πŸ’¬
  • Deutsch πŸ’¬

πŸš€ Super-easy Deployment

  • In the us-east-1 region, open Bedrock Model access > Manage model access > Check Anthropic / Claude 3 Haiku, Anthropic / Claude 3 Sonnet and Cohere / Embed Multilingual then Save changes.
Screenshot

  • Open CloudShell at the region where you want to deploy
  • Run deployment via following commands
git clone https://github.com/aws-samples/bedrock-claude-chat.git
cd bedrock-claude-chat
chmod +x bin.sh
./bin.sh
  • After about 30 minutes, you will get the following output, which you can access from your browser
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.

Architecture

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.

Features and Roadmap

Basic chat features
  • Authentication (Sign-up, Sign-in)
  • Creation, storage, and deletion of conversations
  • Copying of chatbot replies
  • Automatic subject suggestion for conversations
  • Syntax highlighting for code
  • Rendering of Markdown
  • Streaming Response
  • IP address restriction
  • Edit message & re-send
  • I18n
  • Model switch
Customized bot features
  • Customized bot creation
  • Customized bot sharing
  • Publish as stand-alone API
RAG features
  • Web (html)
  • Text data (txt, csv, markdown and etc)
  • PDF
  • Microsoft office files (pptx, docx, xlsx)
  • Youtube transcript
  • Import from S3 bucket
  • Import external existing Kendra / OpenSearch / KnowledgeBase
Admin features
  • Tracking usage fees per bot
  • List all published bot

Deploy using CDK

Super-easy Deployment uses AWS CodeBuild to perform deployment by CDK internally. This section describes the procedure for deploying directly with CDK.

  • Please have UNIX, Docker and a Node.js runtime environment. If not, you can also use Cloud9

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.

  • Clone this repository
git clone https://github.com/aws-samples/bedrock-claude-chat
  • Install npm packages
cd bedrock-claude-chat
cd cdk
npm ci
npm i -g aws-cdk
  • Before deploying the CDK, you will need to work with Bootstrap once for the region you are deploying to. In this example, we will deploy to the us-east-1 region. Please replace your account id into <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
  • You will get output similar to the following. The URL of the web app will be output in 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

Others

Configure text generation / embedding parameters

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: "],
}

EMBEDDING_CONFIG = {
    "model_id": "cohere.embed-multilingual-v3",
    "chunk_size": 1000,
    "chunk_overlap": 200,
}

Remove resources

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.

Language Settings

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

Disable self sign up

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,
  },
  // true -> false
  selfSignUpEnabled: false,
  signInAliases: {
    username: false,
    email: true,
  },
});

External Identity Provider

This sample supports external identity provider. Currently we only support Google. To set up, See SETUP_IDP.md.

Local Development

See LOCAL DEVELOPMENT.

Contribution

Thank you for considering contributing to this repository! We welcome bug fixes, language translation, feature enhancements, and other improvements. Please see following:

RAG (Retrieval Augmented Generation)

See here.

Authors

License

This library is licensed under the MIT-0 License. See the LICENSE file.

About

AWS-native chatbot using Bedrock + Claude

License:MIT No Attribution


Languages

Language:TypeScript 53.2%Language:Python 43.7%Language:JavaScript 1.8%Language:HTML 0.8%Language:Shell 0.3%Language:Dockerfile 0.3%Language:CSS 0.0%