| ```CODE: | |
| tools = [ | |
| { | |
| "name": "get_weather", | |
| "description": "Get the weather in a city", | |
| "parameters": {"type": "object", "properties": {"city": {"type": "string", "description": "The city to get the weather for"}}}} | |
| ] | |
| messages = [ | |
| { | |
| "role": "user", | |
| "content": "Hello! How is the weather today in Copenhagen?" | |
| } | |
| ] | |
| inputs = tokenizer.apply_chat_template( | |
| messages, | |
| enable_thinking=False, # True works as well, your choice! | |
| xml_tools=tools, | |
| add_generation_prompt=True, | |
| tokenize=True, | |
| return_tensors="pt" | |
| ).to(model.device) | |
| outputs = model.generate(inputs) | |
| print(tokenizer.decode(outputs[0])) | |
| ``` | |
| ERROR: | |
| Traceback (most recent call last): | |
| File "/tmp/HuggingFaceTB_SmolLM3-3B_6Wkbs8V.py", line 30, in <module> | |
| inputs = tokenizer.apply_chat_template( | |
| ^^^^^^^^^ | |
| NameError: name 'tokenizer' is not defined | |