Rocketknight1 HF Staff commited on
Commit
63f0fbf
·
verified ·
1 Parent(s): c183ef8

Add a response template and fix tool calls with null content

Browse files

Assistant tool-call messages with `content: None`, as OpenAI-format clients send them, no longer put a literal `None` in the prompt (the same fix as GLM-5.3's template); it should work in Transformers, llama.cpp and vLLM. Also adds a response template, so Transformers' `parse_response` turns the model's output back into a message (reasoning, content and tool calls), matching vLLM's own GLM parser.

Files changed (2) hide show
  1. chat_template.jinja +1 -1
  2. tokenizer_config.json +42 -1
chat_template.jinja CHANGED
@@ -25,7 +25,7 @@ For each function call, output the function name and arguments within the follow
25
  {{- item }}
26
  {%- endif -%}
27
  {%- endfor -%}
28
- {%- else -%}
29
  {{- content }}
30
  {%- endif -%}
31
  {%- endmacro -%}
 
25
  {{- item }}
26
  {%- endif -%}
27
  {%- endfor -%}
28
+ {%- elif content is not none -%}
29
  {{- content }}
30
  {%- endif -%}
31
  {%- endmacro -%}
tokenizer_config.json CHANGED
@@ -29,5 +29,46 @@
29
  "pad_token": "<|endoftext|>",
30
  "padding_side": "left",
31
  "remove_space": false,
32
- "tokenizer_class": "TokenizersBackend"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  }
 
29
  "pad_token": "<|endoftext|>",
30
  "padding_side": "left",
31
  "remove_space": false,
32
+ "tokenizer_class": "TokenizersBackend",
33
+ "response_template": {
34
+ "defaults": {
35
+ "role": "assistant"
36
+ },
37
+ "start_anchor": "<|assistant|>",
38
+ "fields": {
39
+ "reasoning_content": {
40
+ "open_pattern": "<think>|(?=</think>)",
41
+ "close_pattern": "</think>|(?=<tool_call>)",
42
+ "content": "text",
43
+ "repeats": true,
44
+ "join": ""
45
+ },
46
+ "tool_calls": {
47
+ "open_pattern": "<tool_call>\\s*(?P<name>[^<]*?)\\s*(?=<arg_key>|</tool_call>)",
48
+ "close": "</tool_call>",
49
+ "repeats": true,
50
+ "content": "xml-inline",
51
+ "content_args": {
52
+ "tag_pattern": "<arg_key>\\s*(?P<key>.*?)\\s*</arg_key>\\s*<arg_value>(?P<value>.*?)</arg_value>"
53
+ },
54
+ "transform": {
55
+ "type": "function",
56
+ "function": {
57
+ "name": "{name}",
58
+ "arguments": "{content}"
59
+ }
60
+ }
61
+ },
62
+ "content": {
63
+ "close": [
64
+ "<|user|>",
65
+ "<|observation|>",
66
+ "<|endoftext|>"
67
+ ],
68
+ "content": "text",
69
+ "repeats": true,
70
+ "join": ""
71
+ }
72
+ }
73
+ }
74
  }