A demo to using natural language to query SQLite DB
This repository contains code that combines SQLite querying with OpenAI's GPT-3.5-turbo language model. The code allows users to interact with a SQLite database using natural language queries through a chat-like interface.
- Connects to a SQLite database (
chinook.db
) using thesqlite3
library. - Utilizes OpenAI's GPT-3.5-turbo language model for natural language processing.
- Supports querying the database by generating SQL queries based on natural language.
- Retrieves table and column information from the database to assist with query generation.
- Allows users to ask questions about the music database and receive SQL query responses.
-
Clone this repository to your local machine:
git clone git@github.com:JackZong/NaturalSQL.git
-
Install the necessary dependencies:
yarn install
-
Configure the API key and base path by editing the
config.json
file:{ "apiKey": "<your_open_ai_api_key>", "basePath": "<base_path>", // if you are using rapid open ai APIs, this demo based on Rapid API's open ai APIs "rapidApiKey": "<your_rapid_api_key>", "rapidHost": "<rapid_host>" }
-
Ensure that the SQLite database (
chinook.db
) is located in the./db
directory. -
Start the application:
yarn start
-
The application will connect to the database and retrieve the table and column information.
-
The application will use OpenAI's GPT-3.5-turbo language model to generate an SQL query based on the hard-code natural language.
-
The SQL query will be executed against the SQLite database, and the results will be displayed in the console.
- Supports to send message based on user inputs.
This project is licensed under the MIT License.
- OpenAI for providing the GPT-3.5-turbo language model.
- The Chinook Sample Database for the music database used in this example.
- SQLite Node SDK for using node sdk to connect with SQLite
- How to use ChatGPT call functions
- SQLite for the powerful and lightweight database engine.