Views
No views yet
1import time
2import torch
3from transformers import AutoTokenizer, AutoModelForCausalLM, TextStreamer
4
5device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
6finetuned_model = AutoModelForCausalLM.from_pretrained("Mr-Vicky-01/sql-assistant")
7finetuned_model.to(device)
8tokenizer = AutoTokenizer.from_pretrained("Mr-Vicky-01/sql-assistant")
9
10prompt = """<|im_start|>system
11<|im_start|>system
12You are a helpful SQL assistant named Securitron. Your working table is 'scans' with the following schema:
13
14CREATE TABLE scans (
15 id SERIAL PRIMARY KEY,
16 findings_sca INT,
17 findings_secrets INT,
18 findings_compliance INT,
19 findings_iac INT,
20 findings_malware INT,
21 findings_api INT,
22 findings_pii INT,
23 findings_container INT,
24 timestamp TIMESTAMP,
25 total_findings INT,
26 fp_vulnerabilities INT,
27 tp_vulnerabilities INT,
28 unverified_vulnerabilities INT,
29 findings_sast INT,
30 group_id INT,
31 project_link TEXT,
32 project TEXT,
33 repository TEXT,
34 scan_link TEXT,
35 scan_id TEXT,
36 branch TEXT,
37 commit TEXT,
38 tags TEXT,
39 initiator TEXT
40);<|im_end|>
41<|im_start|>user
42Show me yesterday's scan with the fewest API findings.<|im_end|>
43<|im_start|>assistant
44"""
45
46s = time.time()
47
48encodeds = tokenizer(prompt, return_tensors="pt",truncation=True).input_ids.to(device)
49text_streamer = TextStreamer(tokenizer, skip_prompt = True)
50
51# Increase max_new_tokens if needed
52response = finetuned_model.generate(
53 input_ids=encodeds,
54 streamer=text_streamer,
55 max_new_tokens=512,
56 use_cache=True,
57 pad_token_id=151645,
58 eos_token_id=151645,
59 num_return_sequences=1
60 )
61e = time.time()
62print(f'time taken:{e-s}')