
Slonito is a lightweight assistant that helps users generate PostgreSQL queries from natural language prompts. It was developed as part of an academic research project, aiming to support professionals with limited SQL knowledge in creating customized queries with greater speed, accuracy, and confidence.
Slonito API is the backend service responsible for converting natural language prompts into PostgreSQL queries using a fine-tuned Large Language Model (LLM). Built with Python and FastAPI, this API powers the query-generation logic for the Slonito frontend.
🧠 The model was fine-tuned using Gemma 2 2B, optimized to handle SQL generation with accuracy and low resource usage.
🤖 Generates PostgreSQL queries from natural language
🧠 Fine-tuned LLM using supervised learning techniques
⚙️ Modular and language-agnostic – can be reused in other projects
🚀 Built with FastAPI for performance and simplicity
🔐 Designed for local or private server use – ideal for sensitive data
-
Python 3.10+
-
FastAPI
-
Hugging Face Transformers
-
local-gemma (optimized for local inference)
-
PyTorch
-
Uvicorn
-
CUDA-compatible GPU (recommended for inference)
- CUDA Toolkit 12.9
-
Python 3.10+
-
Access to the fine-tuned model or the base model (gemma-2-2b-it)
git clone https://github.com/bellps/slonito-api.git
cd slonito-api
pip install -r requirements.txt
uvicorn main:app --reload --host 0.0.0.0 --port 3001
Create a .env file or export:
HF_TOKEN="your_hf_token"
HF_MODEL="google/gemma-2-2b-it"
HF_TOKENIZER="google/gemma-2-2b-it"
Important
If you’re using local-gemma, make sure your GPU drivers and CUDA are properly set up.
POST /generate
Request body:
{
"prompt": "List the names of all employees with salary above 50000.",
"sql_schema": "CREATE TABLE employees (id INT, name TEXT, salary INT);"
}
Response:
{
"response": "```sql\nSELECT name FROM employees WHERE salary > 50000;\n```"
}
Slonito (Rails) – Web interface for interacting with this API.
Slonito is a pink elephant who loves SQL and decided to help every one that's facing trouble with this language
So, Slonito is like saying “a tiny, tiny elephant” — a playful nod to the project’s lightweight nature and its connection to PostgreSQL. It’s small, helpful, and works hard behind the scenes to make your life with SQL just a bit easier. 🐘✨