import jsonimport torchfrom transformers import AutoTokenizer, AutoModelForCausalLMfrom peft import PeftModel BASE_MODEL = "Qwen/Qwen3-1.7B"ADAPTER_REPO = "YOUR_USERNAME/qwen3-1.7b-function-calling-lora" tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL, trust_remote_code=True)base = AutoModelForCausalLM.from_pretrained( BASE_MODEL, torch_dtype=torch.float16, device_map="auto")model = PeftModel.from_pretrained(base, ADAPTER_REPO) tools = [ { "name": "get_stock_price", "description": "Get real-time stock quote", "parameters": { "type": "object", "properties": {"ticker": {"type": "string"}}, "required": ["ticker"] } }] prompt = f"<|im_start|>system\nYou are a helpful assistant with access to the following functions. Use them if required -\n{json.dumps(tools)}<|im_end|>\n<|im_start|>user\nWhat is the stock price of NVIDIA?<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n" inputs = tokenizer(prompt, return_tensors="pt").to(model.device)with torch.no_grad(): output = model.generate(**inputs, max_new_tokens=128, temperature=0.0) print(tokenizer.decode(output[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))# Output: {"name": "get_stock_price", "arguments": {"ticker": "NVDA"}}