Demo.mp4
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.
- Auto-generate SQL queries from the natural language descriptions
- Translate SQL queries from one dialect to another
- Optimize SQL queries to make them run faster
- Analyze SQL queries to identify potential problems
- Optimize the SQL queries that are used to fetch data from the SQL database
- Analyze the SQL queries that are used in your NextJS application to identify potential problems
- Displays all the data in the form of a table after executing the query on a schema
- Stores the history prompts and the queries generated in No-SQL
Langchain-SQL.Agent.mp4
- Frontend: NextJS/TailwindCSS/Flowbite
- Backend: ExpressJS/NestJS
- Databases: Sqlite/PostgreSQL/MongoDB
- LLM: Langchain SQL Agent with Open AI LLM
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
[email protected]
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
-
Build the image using
docker-compose build --no-cache
-
Run Container with the build image
docker-compose up
-
Open PgAdmin to upload your Database (I will use *.tar file to upload the whole database, you could use any method, and just remember to name the database as mentioned in .env. In my case it is postgres)
-
On
localhost:5050
, login to PgAdmin -
Create a server group
-
Then register server
-
Now restore the database to upload the file
-
After restoring, all the tables will be shown
-
Run the frontend after changing the directory to the client and then using
npm run dev
, available atlocalhost:3000
-
Register and then Sign-in, the application will be redirected towards
/chat
URL -
According to your schema write any prompt to generate an SQL query and the results database contains
Contributions to this project are highly encouraged and appreciated. To help us maintain a high level of quality, please follow these contribution guidelines:
- Fork the repository to your GitHub account.
- Make changes and improvements in your forked repository.
- Test your changes thoroughly.
- Create a well-explained pull request detailing the changes you made and the problems they solve.
- Ensure your pull requests comply with the coding standards and styles followed in the project.
- Be responsive to feedback and iterate on your contributions, if necessary.
- Upon review, your pull request will go through a validation process by the project maintainers. Once approved, your changes will be merged into the main branch, and you will become a contributor to the NextJs Langchain Agents SQL project. We appreciate your efforts in making this project better and more valuable.
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.
This project is licensed under the MIT License.