An AI-powered SQL chatbot built with LangChain, GROQ LLMs, and Streamlit.
ChatSQL lets you query relational databases in plain English and get intelligent, conversational responses.
It supports both a preloaded SQLite database (student.db
) and custom MySQL connections.
- 💬 Chat with your database using natural language
- 🛢️ Supports both SQLite (default) and MySQL
- 🔗 Powered by LangChain SQL Agent and SQLDatabaseToolkit
- ⚡ Uses GROQ LLM (Gemma2-9b-it) for accurate query generation
- 🎛️ Interactive Streamlit UI with message history
- 🧠 Auto-translates queries into SQL statements behind the scenes
- 📊 Example database (
student.db
) preloaded withSTUDENT
table
- Python
- Streamlit
- LangChain
- GROQ LLM (
gemma2-9b-it
) - SQLite / MySQL
- SQLAlchemy
- Clone the Repository
git clone https://github.com/jasoncobra3/ChatSQL.git cd ChatSQL
- Create Virtual Environment
python -m venv venv
- Activate the Virtual Environment
# Windows: venv\Scripts\activate # macOS/Linux: venv/bin/activate
- Install Dependencies
pip install -r requirements.txt
-
Create a
.env
file in root folder withGROQ_API_KEY=your_groq_api_key_here
-
SQLite Database (Default) Run
sqlite.py
to createstudent.db
with sample records.python sqlite.py
This creates a STUDENT
table with sample entries:
Name | Subject | Grade | Marks
--------|---------------|-------|------
Krish | Data Science | A | 90
John | Data Science | B | 100
Mukesh | Data Science | A | 86
Jacob | DEVOPS | A | 50
Dipesh | DEVOPS | A | 35
- MySQL Connection, In the Streamlit sidebar, provide:
- Host
- User
- Password
- Database name
Run the Script in Terminal
streamlit run app.py
├── app.py # Main Streamlit app
├── sqlite.py # Script to generate sample SQLite DB
├── student.db # SQLite DB file (created by sqlite.py)
├── requirements.txt
└── README.md
Contributions, issues, and feature requests are welcome! Feel free to fork this repo and submit a pull request