Using ChatGPT to generate and run SQL queries

Hello,

I am looking to build a pretty simple bot to which you can ask questions about data in the database.

i.e. How many customers do we have from New York?

the SQL is pretty straightforward.

Select count(*) as total from Customers where state='New York';

The process I envision involves two main steps:

  1. The chatbot receives the user’s question and, based on the provided database schema, generates the appropriate SQL query. (This is done by chatGPT)
  2. It then executes this query and delivers the resulting data back to the user. (This will done by an API to the SQL server).

I’m curious to know if there exists an integrated solution capable of handling both these tasks. Any recommendations for an application or platform that can seamlessly integrate chatbot functionality with database querying would be greatly appreciated.

Thank You all.

Use Langchain SQL Agent with OpenAI as the LLM. you can query the database with NLP.