Giter VIP home page Giter VIP logo

awslabs / genai-bedrock-chatbot Goto Github PK

View Code? Open in Web Editor NEW
20.0 3.0 4.0 3.45 MB

A demo application that uses Amazon SageMaker manuals and pricing data tables as an example to explore the capabilities of a generative AI chatbot.

Home Page: https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/develop-advanced-generative-ai-chatbots-by-using-rag-and-react-prompting.html

License: MIT No Attribution

Python 98.55% Dockerfile 1.45%
aws aws-bedrock chatbot genai

genai-bedrock-chatbot's Introduction

GenAI ChatBot on AWS

Introduction

This demo ChatBot application centers around the development of an advanced Chatbot using Amazon Bedrock and AWS's serverless GenAI solution. The solution demonstrates a Chatbot that utilizes the knowledge of the Amazon SageMaker Developer Guide and SageMaker instance pricing. This Chatbot serves as an example of the power of Amazon Bedrock in processing and utilizing complex data sets, and it’s capability of converting natural language into Amazon Athena queries. It employs open source tools like LangChain and LLamaIndex to enhance its data processing and retrieval capabilities. The article also highlights the integration of various AWS resources, including Amazon S3 for storage, Amazon Kendra as vector store to support the retrieval augmented generation (RAG), AWS Glue for data preparation, Amazon Athena for efficient querying, Amazon Lambda for serverless computing, and Amazon ECS for container management. These resources collectively enable the Chatbot to effectively retrieve and manage content from documents and databases, illustrating the potential of Amazon Bedrock in sophisticated Chatbot applications.

Prerequisites

  • Docker
  • AWS CDK Toolkit 2.132.1+, installed installed and configured. For more information, see Getting started with the AWS CDK in the AWS CDK documentation.
  • Python 3.11+, installed and configured. For more information, see Beginners Guide/Download in the Python documentation.
  • An active AWS account
  • An AWS account bootstrapped by using AWS CDK in us-east-1. The us-east-1 AWS Region is required for Amazon Bedrock Claude and Amazon Titan Embedding model access.
  • Enable Claude and Titan embedding model access in Bedrock service.

Target technology stack

  • Amazon Bedrock
  • Amazon ECS
  • AWS Glue
  • AWS Lambda
  • Amazon S3
  • Amazon Kendra
  • Amazon Athena
  • Elastic Load Balancer

Target Architecture

Architecture Diagram

Code

The code repository contains the following files and folders:

  • assets folder – The various static assets like architecture diagram, public dataset, etc are available here
  • code/lambda-container folder– The Python code that is run in the Lambda function
  • code/streamlit-app folder– The Python code that is run as the container image in ECS
  • tests folder – The Python files that is run to unit test the AWS CDK constructs
  • code/code_stack.py – The AWS CDK construct Python files used to create AWS resources
  • app.py – The AWS CDK stack Python files used to deploy AWS resources in target AWS account
  • requirements.txt – The list of all Python dependencies that must be installed for AWS CDK
  • requirements-dev.txt – The list of all Python dependencies that must be installed for AWS CDK to run the unit test suite
  • cdk.json – The input file to provide values required to spin up resources

Note: The AWS CDK code uses L3 constructs and AWS managed IAM policies for deploying the solution.

Deploy Code

The cdk.json file tells the CDK Toolkit how to execute your app.

This project is set up like a standard Python project. The initialization process also creates a virtualenv within this project, stored under the .venv directory. To create the virtualenv it assumes that there is a python3 (or python for Windows) executable in your path with access to the venv package. If for any reason the automatic creation of the virtualenv fails, you can create the virtualenv manually.

To manually create a virtualenv on MacOS and Linux:

python3 -m venv .venv

After the init process completes and the virtualenv is created, you can use the following step to activate your virtualenv.

source .venv/bin/activate

If you are a Windows platform, you would activate the virtualenv like this:

% .venv\Scripts\activate.bat

Once the virtualenv is activated, you can install the required dependencies.

pip install -r requirements.txt

At this point you can now synthesize the CloudFormation template for this code.

export CDK_DEFAULT_REGION=us-east-1
export CDK_DEFAULT_ACCOUNT=123456789
export CDK_ENVIRONMENT=dev
cdk synth

To add additional dependencies, for example other CDK libraries, just add them to your setup.py file and rerun the pip install -r requirements.txt command.

Useful commands

  • cdk ls list all stacks in the app
  • cdk synth emits the synthesized CloudFormation template
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk docs open CDK documentation

Security

See CONTRIBUTING for more information.

License

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

genai-bedrock-chatbot's People

Contributors

amazon-auto avatar dependabot[bot] avatar jundongq avatar praveenflash avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

genai-bedrock-chatbot's Issues

CDK Deployment Fails

I get the following error in my cloudformation stack events when deploying:

Resource handler returned message: "Resource of type 'AWS::ApplicationAutoScaling::ScalableTarget' with identifier 'service/chatbot-stack-dev-ecs-cluster/chatbot-stack-dev-chatbot-service|ecs:service:DesiredCount|ecs' was not found." (RequestToken: 6e97d684-000d-618a-8779-07f0a3b6be46, HandlerErrorCode: NotFound)

Is this a known issue? As far as i can tell I am following the tutorial correctly

cdk --version                                                                                                                                                                                                                           
2.115.0 (build 58027ee)

Any ideas? Furthermore I observe that the deployment takes quite a considerable amount of time ~25min before I reach the error. Is this expected?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.