Skip to main content

SQLGym

This is a portable Gymnasium environment of SQLite database. It is designed for platforms that are not able to use docker. (e.g. users without root privillege)

Setup

Simply pip install sqlgym. If you want to generate ReAct dataset and fine tune a model, please clone the repository and install from source.

# Clone this repository
git clone https://github.com/KYLN24/sqlgym.git
# or via SSH
# git clone git@github.com:KYLN24/sqlgym.git

cd sqlgym

# Install this package
pip install ".[sft]"

Prepare Dataset

# Make a directory to save data
mkdir .data
cd .data

This project currently suppport the BIRD-SQL dataset.

mkdir bird
cd bird

# Download BIRD-SQL Dataset
wget -c https://bird-bench.oss-cn-beijing.aliyuncs.com/train.zip
unzip train.zip
cd train
unzip train_databases.zip
cd ..

wget -c https://bird-bench.oss-cn-beijing.aliyuncs.com/dev.zip
unzip dev.zip
cd dev
unzip dev_databases.zip
cd ..

Usage

from sqlgym import SqlGymEnv
from sqlgym.datasets import BirdDataset

dataset = BirdDataset(
    bird_path=".data/bird",
    mode="dev",
)

env = SqlGymEnv(dataset)

print(env.reset(0))
print(env.step(dataset[0].gt))

SFT

You can use scripts/make_datasets.py to generate a SFT dataset.

python -u scripts/make_datasets.py --bird_path=./data/bird # Dataset will be created at ./data/bird/train.jsonl and ./data/bird/dev.jsonl

You can use scripts/make_react_dataset.py to convert it to ReAct format with thought generated by GPT.

# Edit the script to add your OpenAI api_key.
# Change base_url and other generation parameters as you wish.
python -u scripts/make_react_dataset.py \
       --data_path=.data/bird/train.jsonl \
       --save_path=.data/bird/train_react.jsonl

Then, use scripts/train.py or scripts/train_react.py to fine tune a chat model. The tokenizer should support the apply_chat_template method.

torchrun --nproc_per_node=8 scripts/train.py \
         --model=meta-llama/Llama-2-7b-chat-hf \
         --train_set=.data/bird/train.jsonl \
         --output_dir=.data/output

torchrun --nproc_per_node=8 scripts/train.py \
         --model=meta-llama/Llama-2-7b-chat-hf \
         --train_set=.data/bird/train_react.jsonl \
         --output_dir=.data/output \
         --react

Release files for sqlgym 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for sqlgym 0.1.2
File Interpreter ABI Platform
sqlgym-0.1.2-py3-none-any.whl Python 3 none any Details

Release files / sqlgym-0.1.2-py3-none-any.whl

Download URL sqlgym-0.1.2-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b79806a501644d9aa74d5ad18e6c7bae3f9f3d8b6137b0c3df6a9468e0e90612
BLAKE2b-256 checksum
How to use checksums
009d14dd4463e228e7c156abaaf713ea4c68e29b0ea257eb58bbc4842e302709
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.2 This release

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page