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.
- 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
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
Type in your query in English and wait!
I printed the SQL queries and the responses when testing the app