Skip to content

Rabbit1026HG/sql-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask SQL Assistant

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.

Features

  • 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.

Requirements

  • Python 3.7+
  • MySQL
  • Required Python packages (see Installation)

Installation

  1. Clone the Repository

    git clone <repository-url>
    cd <repository-directory>
  2. Set Up Environment Variables

    Create a .env file to store your environment variables such as API keys, if required.

  3. Install Python Packages

    Install the necessary dependencies using pip:

    pip install -r requirements.txt
  4. Configure Database

    Update SQLDatabase.from_uri in your script to match your database connection URI.

Usage

To run the Flask application, execute:

python app.py

The server will start and be available on http://0.0.0.0:5000.

Endpoints

  • POST /ask: Accepts a JSON payload containing the user's question.
    • Example request:
      {
        "question": "How many products are in the inventory?"
      }

Response

  • If the question is related to the database:

    • Type: database
    • Returns the result of the SQL query.
  • If the question is general:

    • Type: general
    • Provides an AI-generated response.

Example response:

{
  "type": "database",
  "response": "There are 15 products in the inventory."
}

Deployment

Use Waitress to serve the application in a production environment:

python -m waitress --call 'your_script:create_app'

Contributing

Please make sure to update tests as appropriate and adhere to the code style guidelines.

License

MIT License. See LICENSE for more details.

Acknowledgements

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages