Text Generation
Transformers
Safetensors
qwen3
text-to-sql
sql
unknown-schema
tool-use
reinforcement-learning
conversational
text-generation-inference
Instructions to use AIJian/TrustSQL-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AIJian/TrustSQL-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="AIJian/TrustSQL-4B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("AIJian/TrustSQL-4B") model = AutoModelForCausalLM.from_pretrained("AIJian/TrustSQL-4B", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use AIJian/TrustSQL-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "AIJian/TrustSQL-4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AIJian/TrustSQL-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/AIJian/TrustSQL-4B
- SGLang
How to use AIJian/TrustSQL-4B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "AIJian/TrustSQL-4B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AIJian/TrustSQL-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "AIJian/TrustSQL-4B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AIJian/TrustSQL-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use AIJian/TrustSQL-4B with Docker Model Runner:
docker model run hf.co/AIJian/TrustSQL-4B
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -45,6 +45,14 @@ This model is part of the **TRUST-SQL** series, which focuses on building trustw
|
|
| 45 |
|
| 46 |
## Usage
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
```python
|
| 49 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 50 |
import torch
|
|
@@ -57,42 +65,16 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 57 |
device_map="auto"
|
| 58 |
)
|
| 59 |
|
| 60 |
-
|
| 61 |
-
schema = """
|
| 62 |
-
CREATE TABLE employees (
|
| 63 |
-
id INT PRIMARY KEY,
|
| 64 |
-
name VARCHAR(100),
|
| 65 |
-
department VARCHAR(50),
|
| 66 |
-
salary DECIMAL(10,2)
|
| 67 |
-
);
|
| 68 |
-
"""
|
| 69 |
-
|
| 70 |
-
question = "What is the average salary of employees in the Engineering department?"
|
| 71 |
-
|
| 72 |
-
prompt = f"""Given the following database schema:
|
| 73 |
-
{schema}
|
| 74 |
-
|
| 75 |
-
Generate a SQL query to answer the question: {question}"""
|
| 76 |
-
|
| 77 |
-
messages = [{"role": "user", "content": prompt}]
|
| 78 |
text = tokenizer.apply_chat_template(
|
| 79 |
messages,
|
| 80 |
tokenize=False,
|
| 81 |
add_generation_prompt=True,
|
| 82 |
-
enable_thinking=False
|
| 83 |
)
|
| 84 |
-
|
| 85 |
inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 86 |
-
outputs = model.generate(
|
| 87 |
-
|
| 88 |
-
max_new_tokens=512,
|
| 89 |
-
temperature=0.7,
|
| 90 |
-
top_p=0.9,
|
| 91 |
-
)
|
| 92 |
-
response = tokenizer.decode(
|
| 93 |
-
outputs[0][inputs["input_ids"].shape[1]:],
|
| 94 |
-
skip_special_tokens=True
|
| 95 |
-
)
|
| 96 |
print(response)
|
| 97 |
```
|
| 98 |
|
|
|
|
| 45 |
|
| 46 |
## Usage
|
| 47 |
|
| 48 |
+
TrustSQL models are designed for **multi-turn, tool-integrated Text-to-SQL** over unknown schemas. The model explores the database schema via SQL tool calls before generating the final answer.
|
| 49 |
+
|
| 50 |
+
For the full evaluation pipeline, rollout protocol, reward design, and training scripts, please refer to the GitHub repository:
|
| 51 |
+
|
| 52 |
+
👉 **[github.com/JaneEyre0530/TrustSQL](https://github.com/JaneEyre0530/TrustSQL)**
|
| 53 |
+
|
| 54 |
+
### Quick inference
|
| 55 |
+
|
| 56 |
```python
|
| 57 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 58 |
import torch
|
|
|
|
| 65 |
device_map="auto"
|
| 66 |
)
|
| 67 |
|
| 68 |
+
messages = [{"role": "user", "content": "Your NL2SQL prompt here"}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
text = tokenizer.apply_chat_template(
|
| 70 |
messages,
|
| 71 |
tokenize=False,
|
| 72 |
add_generation_prompt=True,
|
| 73 |
+
enable_thinking=False
|
| 74 |
)
|
|
|
|
| 75 |
inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 76 |
+
outputs = model.generate(**inputs, max_new_tokens=512)
|
| 77 |
+
response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
print(response)
|
| 79 |
```
|
| 80 |
|