AWS Assistant GPT-4 ChatBot with Chat-History with Langchain RAG + Lambda + API Gateway + PostgreSQL
- In this tutorial, we'll be creating a GPT-4 AWS Helper ChatBot utilizing Langchain, Lambda, API Gateway, and PostgreSQL PGVector hosted on an EC2 instance as our Vector database.
- AWS Lambda: Responsible for managing API backend Object Detection processing.
- AWS SAM: Utilized for orchestrating AWS serverless services such as Lambda and API Gateway.
- API Gateway: Facilitates the creation of a public REST API.
- AWS EC2: Employed to host the PostgreSQL Vector database.
- PostgreSQL PGVector EC2 Setup with host.
- Data ingestion in PostgreSQL PGVector VectorDB.
- AWS SAM setup in EC2 for deploying Lambda funtion with API Gateway.
- Deployment of Lambda application with SAM using EC2(Docker).
- Testing API with Postman.
- Chatbot Application Demo Streamlit App.
Lambda-App
is directory for SAM App for Lambda & API Gateway.app.py
isStreamlit
app for demo purpose.DataIngestion.py
is used to ingest data in PostgreSQL PGVector DB.connect.py
is used for checking connectivity with PostgreSQL DB hosted in EC2.aws_sample_qa.csv
is CSV sample data that we ingested in DB.
Lambda-SAM-App
│ -- template.yaml - This is template that will create resources like Lambda, API Gateway in AWS account.
│
└───Backend
│ │ -- Lambda_Response_App.py -- Lambda Handler Code
│ │ -- requirements.txt - To install depedencies in Lambda like Langchain, PyPDF, psycopg2, etc
│ └───
- This directory sturcture should be created in EC2 for deploying SAM App from EC2.
- To Download Docker in Ubuntu.
apt install docker.io
- To install AWS CLI in Ubuntu.
apt install awscli
- To setup credentials in AWS CLI.
This will prompt you to enter AWS Credentials.
aws configure --profile <profile-name>
- Sam Installation Follow
- SAM Build
sam build --use-container -parallel
- SAM Deploy
Once this is done successfully, you will see the Lambda function created in your selected region. From Lambda console, you can get rest API URL to invoke API.
sam deploy --stack-name <stack-name> --region <region-name> --guided