Views
No views yet

1
2import torch
3from transformers import pipeline
4
5model_id = "Ary-007/Text-to-sql-llama-3.2"
6
7# Load the pipeline
8pipe = pipeline(
9 "text-generation",
10 model=model_id,
11 device_map="auto",
12)
13
14# Define the schema (Context)
15schema = """
16CREATE TABLE employees (
17 id INT,
18 name TEXT,
19 department TEXT,
20 salary INT,
21 hire_date DATE
22);
23"""
24
25# Define the user question
26question = "Find the name and salary of employees in the 'Engineering' department who earn more than 80000."
27
28# Format the prompt exactly as trained
29prompt = f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
30
31### Instruction:
32Company Database : {schema}
33
34### Input:
35SQL Prompt :{question}
36
37### Response:
38"""
39
40outputs = pipe(
41 prompt,
42 max_new_tokens=200,
43 do_sample=True,
44 temperature=0.1,
45 top_p=0.9
46)
47
48print(outputs[0]["generated_text"])