Views
No views yet


pip install transformers==4.35.21import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3tokenizer = AutoTokenizer.from_pretrained("chatdb/natural-sql-7b")
4model = AutoModelForCausalLM.from_pretrained(
5 "chatdb/natural-sql-7b",
6 device_map="auto",
7 torch_dtype=torch.float16,
8)CC BY-SA 4.0, with extra guidelines for responsible use expanded from the original model's Deepseek license.
You're free to use and adapt the model, even commercially.
If you alter the weights, such as through fine-tuning, you must publicly share your changes under the same CC BY-SA 4.0 license.1inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
2generated_ids = model.generate(
3 **inputs,
4 num_return_sequences=1,
5 eos_token_id=100001,
6 pad_token_id=100001,
7 max_new_tokens=400,
8 do_sample=False,
9 num_beams=1,
10)
11
12outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
13print(outputs[0].split("```sql")[-1])# Task
Generate a SQL query to answer the following question: `{natural language question}`
### PostgreSQL Database Schema
The query will run on a database with the following schema:
<SQL Table DDL Statements>
# SQL
Here is the SQL query that answers the question: `{natural language question}`
'''sql1CREATE TABLE users (
2 user_id SERIAL PRIMARY KEY,
3 username VARCHAR(50) NOT NULL,
4 email VARCHAR(100) NOT NULL,
5 password_hash TEXT NOT NULL,
6 created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
7 );
8CREATE TABLE projects (
9 project_id SERIAL PRIMARY KEY,
10 project_name VARCHAR(100) NOT NULL,
11 description TEXT,
12 start_date DATE,
13 end_date DATE,
14 owner_id INTEGER REFERENCES users(user_id)
15);
16CREATE TABLE tasks (
17 task_id SERIAL PRIMARY KEY,
18 task_name VARCHAR(100) NOT NULL,
19 description TEXT,
20 due_date DATE,
21 status VARCHAR(50),
22 project_id INTEGER REFERENCES projects(project_id)
23);
24CREATE TABLE taskassignments (
25 assignment_id SERIAL PRIMARY KEY,
26 task_id INTEGER REFERENCES tasks(task_id),
27 user_id INTEGER REFERENCES users(user_id),
28 assigned_date DATE NOT NULL DEFAULT CURRENT_TIMESTAMP
29);
30CREATE TABLE comments (
31 comment_id SERIAL PRIMARY KEY,
32 content TEXT NOT NULL,
33 created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
34 task_id INTEGER REFERENCES tasks(task_id),
35 user_id INTEGER REFERENCES users(user_id)
36);1SELECT created_at::DATE AS day, COUNT(*) AS user_count
2FROM users
3GROUP BY day
4ORDER BY user_count DESC
5LIMIT 1;1SELECT p.project_name, t.task_name, COUNT(c.comment_id) AS comment_count
2FROM projects p
3JOIN tasks t ON p.project_id = t.project_id
4JOIN comments c ON t.task_id = c.task_id
5GROUP BY p.project_name, t.task_name
6ORDER BY comment_count DESC
7LIMIT 1;1SELECT
2 SUM(CASE WHEN email ILIKE '%@gmail.com%' THEN 1 ELSE 0 END)::FLOAT / NULLIF(SUM(CASE WHEN email NOT ILIKE '%@gmail.com%' THEN 1 ELSE 0 END), 0) AS gmail_ratio
3FROM
4 users;