This project aims to democratize SQL queries for non-technical users and demonstrate how companies can leverage Large Language Models (LLMs) to make data more accessible.
The project is set up as a Python-based application with the following key components:
sql_gen.py
: Main script for SQL generation logicollama.py
: Integration with the Ollama LLMstreamlit_db_chat.py
: User interface for interacting with the SQL agent- SQL database integration (using SQLite)
- Natural language to SQL query conversion
- SQL query explanation for better understanding
- Database schema exploration through natural language
- Interactive chat interface for querying databases
- Integration with Ollama for local LLM processing
-
Clone the repository
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Deploy the defog/llama-3-sqlcoder-8b model to a Hugging Face Inference Endpoint: a. Go to the Hugging Face website and sign in to your account
b. Navigate to the defog/llama-3-sqlcoder-8b model page
c. Click on "Deploy" and select "Inference Endpoints"
d. Choose your preferred cloud provider and region (e.g., AWS us-east-1)
e. Select the instance type based on your requirements
f. Configure any additional settings as needed
g. Click "Create Endpoint" to deploy the model
h. Once deployed, you'll receive an endpoint URL similar to:
https://mxxhppax9agaovsm.us-east-1.aws.endpoints.huggingface.cloud/v1/
-
Update the
sql_gen.py
file with your Hugging Face API token and the new endpoint URL
- Run the Streamlit app:
streamlit run streamlit_db_chat.py
- Use the chat interface to interact with your database using natural language
This project demonstrates:
- LLM integration for natural language processing
- SQL query generation from natural language
- Database connectivity and querying
- User-friendly interface for database interactions