Skip to content

Converting English to MySQL queries using a custom GPT using a Flask API

License

Notifications You must be signed in to change notification settings

lilNewbie/English-To-MySQL-Query-with-GPT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

English-To-MySQL-Query-with-GPT 👨‍💻

This repository contains the files used to create this custom GPT which converts natural language (English) into MySQL queries and then responds based on the information retrieved.

Features

  • Chatbot-like interface using Streamlit
  • Uses the OpenAI's Completions API
  • Uses a Flask API which retrieves queries from the Chat Complations API and accesses the MySQL database

Run Locally

Clone the project

  git clone https://github.com/lilNewbie/English-To-MySQL-Query-with-GPT.git

Go to the project directory

  cd English-To-MySQL-Query-with-GPT

Install dependencies

  pip install -r requirements.txt

Update the following API Keys in the secrets1.py file.

openai_api_key azure_api_key azure_api_version db_pwd azure_ep

I have added an option to use Azure OpenAI's API key along with OpenAI's API Key

client = OpenAI(api_key=openai_api_key)

client2 = AzureOpenAI(
    azure_endpoint=azure_ep,
    api_key=azure_api_key,
    api_version=azure_api_version
    )

Feel free to experiment with your own schema in the server.py file

 msg_query = [{ "role": "system","content": f"Given the following SQL tables, your job is to write queries given a users request.{Your_Schema}"]
    

Run the web-app

  streamlit run sqlquery.py

Run the server

  flask --app server.py run

Demo

Type in your query in English and wait! sqlImage

I printed the SQL queries and the responses when testing the app sqlImage2

About

Converting English to MySQL queries using a custom GPT using a Flask API

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages