CoolFace
Apppublic

manuelaschrittwieser/SQL-Assistant-Prod

sourceHugging Facemitupdated 9mo agoView on Hugging Face
2likes
App README

Autonomous SQL Assistant Agent

๐Ÿ“‹ System Overview

The Autonomous SQL Assistant is a demonstrative AI agent designed to bridge the gap between natural language inquiries and database execution. Unlike standard "Text-to-SQL" generators that strictly output code, this agent operates within a closed-loop environment: it generates syntax, executes it against a live database, and retrieves the actual data for the user.

The system is powered by Qwen 2.5 (1.5B), fine-tuned via QLoRA on the b-mc2/sql-create-context dataset to ensure high fidelity in SQL syntax generation.

[๐Ÿ”— View Source Code & Documentation](https://github.com/MANU-de/Autonomous-SQL-Agent)


๐Ÿ—๏ธ Technical Architecture

The application runs on a lightweight CPU environment and consists of three core components:

1. The Inference Engine

  • โ€”Model: manuelaschrittwieser/Qwen2.5-1.5B-SQL-Assistant-Prod
  • โ€”Optimization: The model runs in full FP32 precision (CPU optimized).
  • โ€”Role: Translates user intent (e.g., "Who earns the most?") into executable SQLite syntax, utilizing the provided schema context.

2. The Execution Sandbox

  • โ€”Database: A transient SQLite instance.
  • โ€”Schema: employees (id, name, department, salary, hire_date).
  • โ€”Lifecycle: The database is re-instantiated upon every application restart/build to ensure a clean state for testing.

3. The Agent Logic

The SQLAgent class orchestrates the workflow:

  1. 1.Ingest: Receives natural language prompt.
  2. 2.Contextualize: Injects the CREATE TABLE schema into the system prompt.
  3. 3.Generate: produces the SQL query.
  4. 4.Act: Connects to the SQLite cursor, executes the query, and fetches results.
  5. 5.Sanitize: Catches execution errors (e.g., syntax errors) and reports them for debugging.

๐Ÿ’ป Usage Instructions

Interface Guide

The interface is a chat-based UI. You act as the user querying the HR database.

  • โ€”Input: Type natural language questions regarding the employees table.
  • โ€”Output: The agent provides a two-part response:
  • โ€”"Brain" (Internal Monologue): The generated SQL query.
  • โ€”"Result" (Data): The raw tuples returned from the database.

Example Queries

Try copying these prompts to test the agent's capabilities:

ComplexityQuery
SimpleShow me the names of all employees in Sales.
ConditionalWho earns more than 60000?
AggregationCount how many employees work in the Engineering department.
LogicList employees hired after 2020.

โš™๏ธ Local Reproduction

To run this Space locally on your machine (requires Python 3.10+):

  1. 1.Clone the Repository:
bash
    git clone https://huggingface.co/spaces/manuelaschrittwieser/sql-assistant-prod
    cd sql-assistant-prod
  1. 1.Install Dependencies:
bash
    pip install -r requirements.txt
  1. 1.Launch Application:
bash
    python app.py

โš ๏ธ Limitations & Scope

  • โ€”Inference Latency: As this demo runs on CPU Basic hardware, generating the SQL query may take 2-10 seconds depending on server load.
  • โ€”Sandbox Restrictions: Database modifications (INSERT/DROP) are possible but will persist only until the application restarts.
  • โ€”Hallucinations: While fine-tuned, the model may occasionally generate invalid SQL for highly complex queries not covered in the training distribution.

๐Ÿ“œ License

This project is open-source and available under the MIT License.