Views
No views yet



v1.pip install transformers==4.35.21import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3tokenizer = AutoTokenizer.from_pretrained("cfahlgren1/NaturalSQL-6.7B-v0")
4model = AutoModelForCausalLM.from_pretrained(
5 "cfahlgren1/NaturalSQL-6.7B-v0",
6 device_map="auto",
7 torch_dtype=torch.float16,
8)1messages=[
2 { 'role': 'user', 'content': prompt}
3]
4
5inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
6
7# 32023 is the id of <|EOT|> token
8outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, top_k=50, top_p=0.95, num_return_sequences=1, eos_token_id=32023)
9
10print(tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True))
11### Task
Generate a SQL query to answer the following question: `{natural language question}`
### Database Schema
The query will run on a database with the following schema:
'''
<SQL Table DDL Statements>
'''
### Answer
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 );
8
9CREATE TABLE projects (
10 project_id SERIAL PRIMARY KEY,
11 project_name VARCHAR(100) NOT NULL,
12 description TEXT,
13 start_date DATE,
14 end_date DATE,
15 owner_id INTEGER REFERENCES users(user_id)
16);
17
18CREATE TABLE tasks (
19 task_id SERIAL PRIMARY KEY,
20 task_name VARCHAR(100) NOT NULL,
21 description TEXT,
22 due_date DATE,
23 status VARCHAR(50),
24 project_id INTEGER REFERENCES projects(project_id)
25);
26
27CREATE TABLE taskassignments (
28 assignment_id SERIAL PRIMARY KEY,
29 task_id INTEGER REFERENCES tasks(task_id),
30 user_id INTEGER REFERENCES users(user_id),
31 assigned_date DATE NOT NULL DEFAULT CURRENT_TIMESTAMP
32);
33
34CREATE TABLE comments (
35 comment_id SERIAL PRIMARY KEY,
36 content TEXT NOT NULL,
37 created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
38 task_id INTEGER REFERENCES tasks(task_id),
39 user_id INTEGER REFERENCES users(user_id)
40);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;