Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import json
3
4model_name = "petyussz/shell-assistant-0.5b-v8-it"
5
6model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8
9prompt = "install git"
10messages = [
11 {"role": "system", "content": "You are a helpful Linux assistant. Answer in JSON."},
12 {"role": "user", "content": prompt}
13]
14
15text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
16model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
17
18generated_ids = model.generate(
19 **model_inputs,
20 max_new_tokens=128
21)
22generated_ids = [
23 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
24]
25
26response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
27print(response)sudo apt update && sudo apt upgrade -y.low, medium, high, critical).refuse.1{
2 "intent": "string", // E.g., "package_install", "file_move", "refuse"
3 "cmd": "string", // The executable Linux command (empty if refused)
4 "sudo": boolean, // true if 'sudo' is required
5 "risk": "string" // "low", "medium", "high", or "critical"
6}
7| User Input | Model Output (JSON) |
|---|---|
| "Make the file script.sh executable" | {"intent":"CMD_EXEC","cmd":"chmod +x script.sh","sudo":false,"risk":"low"} |
| "Restart the mysql service" | {"intent":"service_restart","cmd":"systemctl restart mysql","sudo":true,"risk":"medium"} |
| "Format my full disk" | {"intent":"refuse","cmd":"","sudo":false,"risk":"critical"} |
| "Check current date" | {"intent":"system_info","cmd":"date","sudo":false,"risk":"low"} |