Skip to content

a LangChain SQL Agent that enables intuitive interaction with SQL databases

License

Notifications You must be signed in to change notification settings

kardSIM/SQL_langchain_agent

Repository files navigation

SQL_langchain_agent

Description

This LangChain SQL Agent enables intuitive interaction with SQL databases by translating natural language queries into SQL statements, simplifying data retrieval and processing for users without SQL expertise.

Key Features

This agent Utilize the Llama3-8B LLM model as its reasoning engine and as language generator, enhancing the agent's ability to understand and process complex natural language queries.

it also comes pre-loaded with three powerful tools:

  1. SQLDatabaseToolkit: Facilitates seamless query translation and efficient data retrieval from SQL databases.

  2. PythonREPLTool: Enables running Python code in a separate thread it is used to process data, allowing for advanced data manipulation and analysis.

  3. FileManagementToolkit: Allow Performing various file operations such as reading, writing, deleting, moving, and listing files.

Database

The database used in this example is the PostgreSQL Pagila database, a sample DVD rental database that is ideal for experimentation. To set it up using Docker, run the following command:

sh run-pg-pagila-docker.sh pagila_postgresql_docker

This script performs several actions :

  1. Builds the Docker container: Initializes the environment for running PostgreSQL.
  2. Downloads the Pagila database: Retrieves the necessary data and schema files.
  3. Instantiates the cluster: pre-configuration of the database.

Once the setup is finished connect to the Pagila database using the following command:

psql -U postgres -d pagila

Create a new user role and grant him group permission :

CREATE ROLE new_user WITH LOGIN PASSWORD 'password';
GRANT pagila_dba TO new_user;

Run the agent

First, claim your API key from https://console.groq.com/keys and store it in the .env file.

Run the Streamlit Application:

streamlit run main.py

Then enter the created account credentials to log in to the database .

Once logged in, you can start querying.

Results

The SQL Agent can :

  1. Answer Database-Related Questions

  2. Process, Create and Save Plots

  3. Return code && SQL Statements

  4. Save output as text

  5. etc.

NB: To modify behavior or customize responses, visit the template.py file."

These are some query responses showcasing prominent results with such technology in the future :

Screenshot1
Audio 1 Waveform
Screenshot1
Audio 1 Waveform
Screenshot1
Audio 1 Waveform

About

a LangChain SQL Agent that enables intuitive interaction with SQL databases

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published