The Ask SQL is a project that utilizes OpenAI's natural language processing capabilities to translate user-generated questions into SQL queries. This project aims to simplify the process of querying databases by allowing users to express their questions in plain language, which is then converted into a structured SQL query based on the database schema, which is directly connected to the chatbot.
- Docker
- OpenAI API key
-
Clone the repository:
git clone https://github.com/yossilevi94/ask-sql-chatbot.git
-
Navigate to the project directory:
cd ask-sql-chatbot
-
Create a
.env
filecd .env.example .env
-
Set up the OpenAI API Key in the
.env
fileOPENAI_API_KEY=..................
-
Write a database DDL query in the
docker/init.sql
file to simulate your database if it doesn't exist. E.g.:CREATE TABLE IF NOT EXISTS users ( id UUID PRIMARY KEY NULL DEFAULT gen_random_uuid(), "name" TEXT NOT NULL, handle TEXT NOT NULL, created_at TIMESTAMP NOT NULL DEFAULT NOW(), updated_at TIMESTAMP NOT NULL DEFAULT NOW() ); CREATE TABLE IF NOT EXISTS locations ( id UUID PRIMARY KEY NULL DEFAULT GEN_RANDOM_UUID(), latitude FLOAT NOT NULL, longitude FLOAT NOT NULL ); CREATE TABLE IF NOT EXISTS tweets ( id UUID PRIMARY KEY NULL DEFAULT GEN_RANDOM_UUID(), created_at TIMESTAMP NOT NULL DEFAULT NOW(), "text" TEXT NOT NULL, "owner" UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, "location" UUID NOT NULL REFERENCES locations(id) ON DELETE CASCADE );
-
Build and run the Docker containers
docker compose up -d --build
The chatbot will be available at http://localhost:7860