This project provides a Python interface for converting natural language questions into SQL queries using OpenAI's language models. It includes automatic schema detection, query validation, and error handling.
- Natural language to SQL conversion
- Automatic database schema detection
- Case-sensitive table name handling
- Query validation before execution
- Smart schema filtering based on context
- Error handling with helpful suggestions
Run the following commands to create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On macOS/Linux
venv\Scripts\activate # On Windows
pip install -r requirements.txt
Create a .env
file in the project directory with the following content:
DATABASE_URL=postgresql://user:password@host:port/database_name
OPENAI_API_KEY=<<API_KEY>>
QDRANT_URL=localhost
QDRANT_PORT=6333
Run the following command to process the database schema:
python digest_schema.py
Execute this command to start the chat interface:
python chat_interface.py