File size: 899 Bytes
2a02299
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a316b2
2a02299
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
```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