import torchimport jsonfrom transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfigfrom peft import PeftModel model_id = "openbmb/MiniCPM5-2B"adapter_id = "antontuzovAI/MiniCPM5-2B-xLAM-Agent-LoRA" # Replace with your actual repo ID bnb_config = BitsAndBytesConfig( load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.bfloat16,) tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)tokenizer.pad_token = tokenizer.eos_token base_model = AutoModelForCausalLM.from_pretrained( model_id, quantization_config=bnb_config, device_map="auto", trust_remote_code=True) # Load the Agent LoRAmodel = PeftModel.from_pretrained(base_model, adapter_id)model.eval() # Define Toolstools = [ { "name": "get_weather", "description": "Get current weather.", "parameters": {"city": {"type": "string", "required": True}} }] prompt = f"""You are a strict tool-calling agent. Output ONLY JSON.Tools: {json.dumps(tools)}User: What is the weather in Tokyo?Assistant:""" inputs = tokenizer(prompt, return_tensors="pt").to(model.device)outputs = model.generate(**inputs, max_new_tokens=64, do_sample=False)print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))# Expected Output: [{"name": "get_weather", "arguments": {"city": "Tokyo"}}]