This project is a Python-based web application built with Flask that uses AI language models to answer questions related to an SQL database. It can distinguish between general and database-specific queries and respond accordingly.
- SQL Database Integration: Connects to a MySQL database to fetch useful information.
- AI-Powered Queries: Uses language models to interpret and answer both database-related and general queries.
- Flask API: Provides an endpoint to query the assistant.
- Error Handling: Includes basic error handling for incoming requests.
- Python 3.7+
- MySQL
- Required Python packages (see Installation)
-
Clone the Repository
git clone <repository-url> cd <repository-directory>
-
Set Up Environment Variables
Create a
.env
file to store your environment variables such as API keys, if required. -
Install Python Packages
Install the necessary dependencies using pip:
pip install -r requirements.txt
-
Configure Database
Update
SQLDatabase.from_uri
in your script to match your database connection URI.
To run the Flask application, execute:
python app.py
The server will start and be available on http://0.0.0.0:5000
.
- POST /ask: Accepts a JSON payload containing the user's question.
- Example request:
{ "question": "How many products are in the inventory?" }
- Example request:
-
If the question is related to the database:
- Type:
database
- Returns the result of the SQL query.
- Type:
-
If the question is general:
- Type:
general
- Provides an AI-generated response.
- Type:
Example response:
{
"type": "database",
"response": "There are 15 products in the inventory."
}
Use Waitress
to serve the application in a production environment:
python -m waitress --call 'your_script:create_app'
Please make sure to update tests as appropriate and adhere to the code style guidelines.
MIT License. See LICENSE
for more details.