Table of Contents
SQL Speaker is an API that converts natural language text into SQL statements for querying a Snowflake database. The API is designed to simplify database interactions, making it accessible to users without extensive SQL knowledge (Business stakeholders, Managers). This enables quick and easy data retrieval from a database by simply describing the data request in plain English.
This app can be installed running Docker (recommended) or locally.
- Create a Snowflake account : https://www.snowflake.com
- Get an OpenAI API key, see : https://platform.openai.com/docs/quickstart?context=python
- Install Python : https://www.python.org/downloads
- Install Docker Desktop : https://www.docker.com/products/docker-desktop
- On your Snowflake account, if you have not any database created yet, create a database and schema, and copy/paste both the
create.sql
theninsert.sql
scripts in order to have data to query. - Rename the
.env.example
file to.env
and fill the variables with your values. - Run Docker on your laptop
- Run
docker build -t sql-speaker .
. It will build the API's Docker image. - Run
start.sh
file. It will run a container using the previous built image.
The API is available on port 5000 with endpoint /ask
. A typical request should be as the following :
{
"query": "What is the total sales revenue for each product category ?",
"sql_in_answer": false,
"sql_mode": false
}
- Set
sql_in_answer
totrue
to include the query generated by OpenAI API in the response. - Set
sql_mode
totrue
to make a plain SQL query. OpenAI API will not be called and the query will be directly addressed to Snowflake.
A web UI is available here : https://github.com/sayyidka/sql-speaker-chatbot
Distributed under the MIT License. See LICENSE.txt
for more information.
Wadieh Karbal - https://www.linkedin.com/in/wadieh-k-865b40181/