You ask a question in plain English, describe your database tables and columns, and SQLSlave generates the SQL query for you. It uses a CodeLlama-7B-Instruct model fine-tuned on the Spider text-to-SQL dataset with QLoRA.
python -m venv venv
.\venv\Scripts\Activate.ps1
python -m pip install -r requirements.txtpython -m cli.download_spiderDownloads the Spider dataset and converts it into:
spider\tables.jsonspider\train_spider.jsonspider\dev.jsonconverted_spider\train.jsonlconverted_spider\validation.jsonl
python -m cli.trainRuns QLoRA fine-tuning for 1 epoch and saves the adapter to artifacts\qlora_adapter.
Optional flags: --num-train-epochs, --learning-rate, --eval-steps.
python -m cli.evalRuns exact-match accuracy on the validation set.
uvicorn api.app:app --host 0.0.0.0 --port 8000Open another terminal:
streamlit run ui/streamlit_app.pyOpen http://127.0.0.1:8501 in your browser. Enter your question, define the schema (tables, columns, PKs, FKs), and generate SQL.
Set $env:ADAPTER_PATH to use a custom adapter path.
curl -X POST http://127.0.0.1:8000/generate -H "Content-Type: application/json" -d "{\"question\":\"Show total sales by region from orders table\",\"schema\":[{\"name\":\"orders\",\"columns\":{\"region\":{},\"amount\":{}}}]}"- Docker Desktop with WSL 2 backend
- NVIDIA Container Toolkit for GPU passthrough
docker compose builddocker compose upThe API is available at http://localhost:8000. Open http://localhost:8000/docs for the interactive Swagger UI.
docker compose run --service-ports app streamlit run ui/streamlit_app.py --server.port 8501Open http://localhost:8501 in your browser.
docker compose run app python cli/train.pyThe QLoRA adapter is saved to artifacts/qlora_adapter/ — this directory is volume-mounted (./artifacts:/app/artifacts), so the trained weights persist on your host machine and are immediately available to the API without rebuilding the image.
Set environment variables to use a different base model or adapter path:
docker compose run -e BASE_MODEL_ID="codellama/CodeLlama-7b-Instruct-hf" -e ADAPTER_PATH="artifacts/qlora_adapter" app