AI Chatbot powered by Amazon Bedrock ๐Ÿš€๐Ÿค–

ยท

3 min read

Introduction

I have created a sample chatbot application that uses Chainlit and LangChain to showcase Amazon Bedrock.

You can interact with the AI assistant while switching between multiple models.

This sample application has been tested in the following environments:

  • AWS Region: us-east-1

  • AWS Copilot CLI: v1.30.1

  • Python: v3.11.5

  • boto3: v1.28.57

  • LangChain: v0.0.305

  • Chainlit: v0.7.0

Note: To support the GA Version of the Bedrock API, make sure to use versions of LangChain and boto3 that are newer than those mentioned above.

Source Code

Check out my GitHub repository!

Start using Bedrock

Before you can start using Amazon Bedrock, you must request access to each model. To add access to a model, go to the Model Access section in the Bedrock console and click Edit.

Select the models you want to use and save the settings.

Note: Third-party models such as Jurassic-2 and Claude require access through the AWS Marketplace. This means you will also be charged a Marketplace fee for using the model.

It will take some time for each model to become available; models with an Access status of Access granted are ready for use.

Note: Some models, such as Titan Text G1 - Express, are in Preview and may not be immediately available.

How to Deploy

The GitHub repository for the sample application contains a manifest file for deploying the container to AWS App Runner using the AWS Copilot CLI.

Follow these steps to deploy:

  1. Install the AWS Copilot CLI if necessary

     sudo curl -Lo /usr/local/bin/copilot https://github.com/aws/copilot-cli/releases/latest/download/copilot-linux && sudo chmod +x /usr/local/bin/copilot
    
  2. Deploy to App Runner!

     export AWS_REGION=us-east-1
     copilot app init bedrockchat-app
     copilot deploy --name bedrockchat --env dev
    

If the deployment is successful, access the URL displayed in the message. If the following screen appears, the deployment has succeeded!

To delete an environment, execute the following command:

copilot app delete

How to use the app

The model, temperature, and maximum token size can be changed from the Settings panel.

The sample code allows you to choose between Claude v2, Jurassic-2 Ultra, and Amazon Titan Text G1 - Express. This enables you to compare performance while switching between models.

Note: As of 9/29/2023, Amazon Titan Text G1 - Express is in Preview status. It will be rolled out gradually, so it may not be available for some accounts.

You can enjoy a free-flowing conversation with the AI assistant! The conversation history during the session is retained, allowing it to reply to you while considering the context.

I hope this will be of help to someone else.