Views
No views yet
1### Instruction:
2Provide the system prompt.
3
4### Dialect:
5Specify the SQL dialect (e.g., MySQL, PostgreSQL, SQL Server, etc.).
6
7### Context:
8Provide the database schema including table names, column names, and data types.
9
10### Input:
11User's query.
12
13### Response:
14Expected SQL query output based on the input and context.
151<s>
2<|system|>
3{ Instruction / System Prompt }
4<|user|>
5{ Context / User Query } <|end|>
6<|assistant|>1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4# Define the model and tokenizer
5model_id = "HridaAI/Hrida-T2SQL-3B-V0.1"
6tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
7model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, trust_remote_code=True)
8
9# Define the context and prompt
10prompt = """
11Answer to the query will be in the form of an SQL query.
12### Context: CREATE TABLE Employees (
13 EmployeeID INT PRIMARY KEY,
14 FirstName VARCHAR(50),
15 LastName VARCHAR(50),
16 Age INT,
17 DepartmentID INT,
18 Salary DECIMAL(10, 2),
19 DateHired DATE,
20 Active BOOLEAN,
21 FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID)
22);
23
24CREATE TABLE Departments (
25 DepartmentID INT PRIMARY KEY,
26 DepartmentName VARCHAR(100),
27 Location VARCHAR(100)
28);
29### Input: Write a SQL query to select all the employees who are active.
30### Response:
31"""
32# Prepare the input
33messages = [{"role": "user", "content": prompt}]
34inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True)
35
36# Generate the output
37outputs = model.generate(inputs, max_length=300)
38print(tokenizer.decode(outputs[0]))
39
401from mlx_lm import generate, load
2
3model,tokenizer = load("HridaAI/Hrida-T2SQL-3B-V0.1")
4
5prompt = """
6Answer to the quey will be in the form of SQL query.
7### Context: CREATE TABLE Employees (
8 EmployeeID INT PRIMARY KEY,
9 FirstName VARCHAR(50),
10 LastName VARCHAR(50),
11 Age INT,
12 DepartmentID INT,
13 Salary DECIMAL(10, 2),
14 DateHired DATE,
15 Active BOOLEAN,
16 FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID)
17);
18
19CREATE TABLE Departments (
20 DepartmentID INT PRIMARY KEY,
21 DepartmentName VARCHAR(100),
22 Location VARCHAR(100)
23); ### Input: Write a SQL query to select all the employees who are active. ### Response:"""
24
25response = generate(model=model,tokenizer=tokenizer,prompt=prompt, verbose=True)
26