🚀 Python-based Chat Assistant for SQLite Database
🔗 Live API: Chat Assistant API
This project is a Flask-based Chat Assistant that interacts with an SQLite database to answer user queries. It accepts natural language input, converts it into SQL queries, fetches data, and responds in a clear, formatted manner.
✔ Accepts natural language queries.
✔ Converts user input into SQL queries.
✔ Retrieves relevant data from an SQLite database.
✔ Handles invalid queries & errors gracefully.
✔ Supports various queries, including:
- "Show me all employees in the [department] department."
- "Who is the manager of the [department] department?"
- "List all employees hired after [date]."
- "What is the total salary expense for the [department] department?"
- Python (Core programming language)
- SQLite (Database management)
- Flask (Web API)
- NLTK (For natural language processing, if needed)
- SQLAlchemy (For database interaction)
git clone https://github.com/Subramanyabs15/Chat_Assistant.git
cd Chat_Assistant
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
Ensure employees.db
exists with this schema:
CREATE TABLE Employees (
ID INTEGER PRIMARY KEY,
Name TEXT NOT NULL,
Department TEXT NOT NULL,
Salary INTEGER NOT NULL,
Hire_Date TEXT NOT NULL
);
CREATE TABLE Departments (
ID INTEGER PRIMARY KEY,
Name TEXT NOT NULL,
Manager TEXT NOT NULL
);
If missing, create it manually or use create_db.py
.
python app.py
The API will be accessible at:
http://127.0.0.1:5000
If using Railway, use your live URL:
https://chatassistant-production-2fb6.up.railway.app
Method | Endpoint | Description |
---|---|---|
GET | / |
Returns "Chat Assistant API is running!" |
POST | /chat |
Accepts a user query and returns results |
curl -X POST "https://chatassistant-production-2fb6.up.railway.app/chat" \
-H "Content-Type: application/json" \
-d '{"query": "Who is the manager of the Sales department?"}'
Method: POST
URL: https://chatassistant-production-2fb6.up.railway.app/chat
Headers: { "Content-Type": "application/json" }
Body (JSON):
{
"query": "Who is the manager of the Sales department?"
}
✅ Expected Response:
{"response": [["Alice"]]}
- User enters a query in natural language.
- Query gets converted into SQL using
query_parser.py
. - SQLite database fetches relevant data.
- The response is formatted & returned in JSON.
✔ Handles invalid department names (returns appropriate message).
✔ Gracefully manages incorrect query formats.
✔ Returns “No results found” for queries with no matching data.
🚧 Limited NLP Support: Complex sentence handling can be improved.
🚧 Enhancements Needed for Multi-Condition Queries.
🚧 User Authentication: Not yet implemented, could be a future feature.
Feel free to fork the repository and submit pull requests with improvements! Your contributions are welcome! 😊🎯
This project is open-source and available under the MIT License.