Views
No views yet
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_id = "TheArchitect256/qwen3.5-2b-triage-master"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForCausalLM.from_pretrained(model_id, dtype=torch.bfloat16, device_map="auto")
8
9alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
10
11### Instruction:
12{}
13
14### Input:
15{}
16
17### Response:
18"""
19
20instruction = """Available tools:
211. [STOCK_CHECK]: Verifies if an item is available in the warehouse inventory.
222. [SHIPPING_CALC]: Calculates delivery rates and times based on postal codes.
23
24User Query: Can you tell me if we still have the RTX 4060 graphics card in our warehouse?"""
25
26prompt = alpaca_prompt.format(instruction, "")
27inputs = tokenizer(text=prompt, return_tensors="pt").to(model.device)
28
29outputs = model.generate(**inputs, max_new_tokens=20, do_sample=False, pad_token_id=tokenizer.eos_token_id)
30print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
31
32# **Note:** The model does not reliably emit an EOS token after the tool label, so `generate()` may continue producing text past the intended answer. Always truncate the output to the first `[TOOL_NAME]`-style tag rather than relying on generation length alone:
33
34import re
35match = re.search(r"\[[A-Z_]+\]", response)
36clean_response = match.group(0) if match else response.strip()