import jsonimport torchfrom transformers import AutoModelForCausalLM, AutoTokenizer model_path = "." tokenizer = AutoTokenizer.from_pretrained(model_path)model = AutoModelForCausalLM.from_pretrained( model_path, torch_dtype=torch.bfloat16, device_map="auto",).eval() with open("tools.json", encoding="utf-8") as file: tools = json.load(file) with open("system_prompt.txt", encoding="utf-8") as file: system_prompt = file.read().strip() messages = [ { "role": "system", "content": system_prompt, }, { "role": "user", "content": ( "Could you find me a nonstop flight from Shanghai to Seattle next Friday evening?" ), }] text = tokenizer.apply_chat_template( messages, tools=tools, tokenize=False, add_generation_prompt=True, enable_thinking=False,)inputs = tokenizer( text, add_special_tokens=False, return_tensors="pt",).to(model.device) with torch.inference_mode(): output = model.generate( **inputs, max_new_tokens=512, do_sample=False, ) response = tokenizer.decode( output[0, inputs.input_ids.shape[1]:], skip_special_tokens=True,)print(response)