Skip to content

This program is designed to translate natural language statements into SQL queries using OpenAI API, pandas library, and sqlalchemy. It is useful for those who are not familiar with SQL syntax and want to query databases using natural language.

Notifications You must be signed in to change notification settings

anaiscmateus/OpenAI-NLPtoSQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Natural Language to SQL Query Translator

This program is designed to translate natural language statements into SQL queries using OpenAI API, pandas library, and sqlalchemy. It is useful for those who are not familiar with SQL syntax and want to query databases using natural language.

Installation

To use this program, you will need to install the following dependencies:
  1. OpenAI API (https://beta.openai.com/docs/)
  2. pandas library (https://pandas.pydata.org/)
  3. sqlalchemy (https://www.sqlalchemy.org/)

You can install these dependencies using pip by running the following command:

pip install openai pandas sqlalchemy

Usage

Before running the program, you will need to set two variables:
  1. openai.api_key
  2. dataset

How to obtain and set the openai.api_key variable:

  1. To set up an OpenAI API key. You can sign up for an API key on the OpenAI website: https://beta.openai.com/signup/.
    Note that it is very important that this API Key is kept secure. Do not share it with anyone else.
  2. Once you have an API key, create a file named .env in the root directory of this project and add the following line:

    OPENAI_API_KEY="YOURAPIKEY"

  3. Then, set the variable in the main.py file: openai.api_key = environ.get('OPENAI_API_KEY')

How to set the dataset variable:

  1. Make sure that you have downloaded your dataset to somewhere on your computer
  2. Copy the file path of your dataset and set it to the variable in the main.py file: dataset=r"YOURFILEPATH"

Running the program

To run the program, run the main.py file and enter a natural language statement when prompted. The program will use the OpenAI API to generate a SQL query based on your statement, which will then be executed using sqlalchemy.

About

This program is designed to translate natural language statements into SQL queries using OpenAI API, pandas library, and sqlalchemy. It is useful for those who are not familiar with SQL syntax and want to query databases using natural language.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages