Syed007Hassan / Chat-To-Your-Database

Natural language querying allows users to interact with databases more intuitively and efficiently. By leveraging the power of LangChain, SQL Agents, and OpenAI’s Large Language Models (LLMs) like GPT, we have created an application that enable users to query databases using NLP
https://medium.com/@syed007hassan/unlocking-the-power-of-langchains-sql-agent-a-deep-dive-into-natural-language-database-4b2b2dcd6d18
MIT License
41 stars 3 forks source link
docker express langchain mongodb nestjs nextjs openai postgresql sql-agent
# Chat To Your Database

image

https://github.com/user-attachments/assets/0260ee61-50da-41ba-aead-e9197d4b5947

Table Of Contents

Introduction

Natural language querying allows users to interact with databases more intuitively and efficiently. By leveraging the power of LangChain, SQL Agents, and OpenAI’s Large Language Models (LLMs) like ChatGPT, we have created an application that enables users to query databases using NLP. All it needs a SQL-based schema, and it can perform any read and write action to that schema.

This is an experimental app to test the abilities of LLMs to query SQL databases using SQL Agents provided by Langchain. To use it, you should have an OPENAI_API_KEY.

Features

Examples

Sample database SQLite

Sample northwind database

See it in action

https://github.com/Syed007Hassan/NextJs-Langchain-Agents-SQL/assets/104893311/2616a2b5-0512-47f0-8271-014a6d243213

Sample database PostgreSQL

DVDRental

See it in action

pg res

Tech Stack

Getting Started

Add Env file

After cloning the repo, change the directory to nest_api, and add a .env file.

OPENAI_API_KEY=sk-xxx
# Docker environment variables
DB_TYPE=postgres
PG_HOST=postgres
PG_USER=postgres
PG_PASSWORD=postgres
PG_DB=postgres
PG_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=postgres
PGADMIN_DEFAULT_EMAIL=admin@pgadmin.com
PGADMIN_DEFAULT_PASSWORD=admin
MONGO_INITDB_ROOT_USERNAME=root
MONGO_INITDB_ROOT_PASSWORD=pass12345
MONGO_URL=mongodb://root:pass12345@mongodb:27017/chatwithdb?authSource=admin
PORT=5000

Running the APP using Docker Compose with your own Database (PostgreSQL)

Contribution Guidelines

Contributions to this project are highly encouraged and appreciated. To help us maintain a high level of quality, please follow these contribution guidelines:

Please follow the contribution guidelines outlined in the Contributing.md file in this repository, to make sure that your contributions align with the project standards.

License

This project is licensed under the MIT License.