Skip to content

garystafford/llm-langchain-sql-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NLQ on Amazon RDS using Amazon SageMaker, LangChain, and LLMs

Source code for the upcoming blog post, Generative AI for Analytics: Performing Natural Language Queries on Amazon RDS using SageMaker, LangChain, and LLMs. Learn to use LangChain's SQL Database Chain and Agent with large language models to perform natural language queries (NLQ) of Amazon RDS for PostgreSQL.

Architecture

Amazon SageMaker Environment

Kernel: Base Python 3.0 (Python 3)

Instance type: ml.m5.medium

Using dotenv

Your .env files should look as follows:

# add required values, then rename this file to .env
# mv env.txt .env

# API Keys
OPENAI_API_KEY=<your_value_here>
ANTHROPIC_API_KEY=<your_value_here>

# Demo 1: Amazon RDS Connection 
RDS_ENDPOINT=<your_value_here>
RDS_PORT=<your_value_here>
RDS_USERNAME=<your_value_here>
RDS_PASSWORD=<your_value_here>
RDS_DB_NAME=<your_value_here>

# Demo 2: Amazon Redshift Connection 
REDSHIFT_HOST=<your_value_here>
REDSHIFT_PORT=<your_value_here>
REDSHIFT_USERNAME=<your_value_here>
REDSHIFT_PASSWORD=<your_value_here>
REDSHIFT_DATABASE=<your_value_here>

Checking RDS Connection from SageMaker Notebook

# Amazon SageMaker terminal
yum install bind-utils -y

# Get your SageMaker Notebook environment IP
dig +short txt ch whoami.cloudflare @1.0.0.1

# Curl RDS database instance to check connectivity
curl -v ******.******.us-east-1.rds.amazonaws.com:5432

Notebook Formatting

jupyter-black was used to format notebooks and Steamlit app.

pip install black "black[jupyter]"

black *.ipynb
black *.py

The contents of this repository represent my viewpoints and not of my past or current employers, including Amazon Web Services (AWS). All third-party libraries, modules, plugins, and SDKs are the property of their respective owners.

About

Using LangChain's SQL Database Chain and Agent with various LLMs to perform Natural Language Queries (NLQ) of an Amazon RDS for PostgreSQL database.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published