import json, torchfrom huggingface_hub import hf_hub_downloadfrom peft import PeftModelfrom transformers import AutoModelForCausalLM, AutoTokenizer base_id, adapter_id = "Qwen/Qwen3-1.7B", "snehitsh/qwen3-1.7b-toolcall-lora-v1"tok = AutoTokenizer.from_pretrained(base_id)model = AutoModelForCausalLM.from_pretrained(base_id, dtype=torch.bfloat16, device_map="cuda") # older transformers: torch_dtype=model = PeftModel.from_pretrained(model, adapter_id).eval()tools = json.load(open(hf_hub_download(adapter_id, "tools.json"))) # the five tool schemas messages = [ {"role": "system", "content": "You are a helpful assistant. The current date and time is 2026-02-17 14:20 (Tuesday)."}, {"role": "user", "content": "remind me tomorrow at 7pm to cook dinner"},]prompt = tok.apply_chat_template(messages, tools=tools, add_generation_prompt=True, tokenize=False, enable_thinking=False) # trained in non-thinking mode onlyinputs = tok(prompt, return_tensors="pt").to("cuda")out = model.generate(**inputs, max_new_tokens=256, do_sample=False)print(tok.decode(out[0, inputs.input_ids.shape[1]:], skip_special_tokens=False))# <tool_call># {"name": "set_reminder", "arguments": {"message": "cook dinner", "time": "2026-02-18 19:00"}}# </tool_call><|im_end|>