How to build simple ChatApp using Amazon bedrock, langchain and Streamlit?

How to build simple ChatApp using Amazon bedrock, langchain and Streamlit?

Amazon Bedrock is a fully managed, serverless service that provides access to Foundation Models (FM) from leading AI companies such as Meta, Cohere, Anthropic, AI21 Labs, Mistral AI, and Amazon through a single API. It enables the development of generative AI applications focusing on security, privacy, and responsible AI practices. With Bedrock, you can easily experiment with and compare these Foundation Models using your data, leveraging techniques like fine-tuning, Retrieval-Augmented Generation (RAG), and building enterprise-grade agents. Creating a ChatApp with Amazon Bedrock is straightforward. First, ensure your Bedrock service has access to the desired model by sending an access request through the Bedrock configuration. Once access is granted, you can use the model ID in your application.

Step 1: Apply for access to the Foundation models.

Login to your AWS user and go to the Amazon bedrock services. You can request/modify access to these models from Bedrock Configurations at the lower left menu bar.

Amazon bedrock model access

Step 2: Select the Providers

You can start with any of the models you have access to from the providers listed in the Getting Started guide.

Select model providers

Step 3: Select the model for your application.

Amazon Bedrock providers

Step 4: Get the model ID from the selected model
Copy the Model ID to use in your chat application. If you want to try it out, you can directly open it in the playground. Here, I have selected the Anthropic Claude-3.5 sonnet.

Step 5: Setting up the virtual environment

Once you have access to the model and its ID, the actual work begins. You’ll need to set up a local Python virtual environment. If you’re unsure how to do this, refer to this article for guidance.

Step 6: Install all the requirements in your virtual environment.

Follow this GitHub for this project. We need to have boto3, langchain and streamlit to build this chatapp. Install from this requirement.txt.

pip install -r /path/to/requirements.txt

Step 7: Clone this Github Project
Clone this GitHub project and modify it as needed. Try out app_claude3_local.py to run. To run it in your local VS Code, you must first set it up and connect it to your AWS Profile which is credentials you can get it from AWS account. Setup your aws_access_key_id and aws_secret_access_key.

Step 8: Run the Code

streamlit run app_claude3_local.py

Step 9: Demo

Bedrock chatapp

Chatapp with queries

Step 10: Host the application with Streamlit
You can try out the live version of it here. But you need to setup code as in app_claude3.py

Leave a Reply

Your email address will not be published. Required fields are marked *