[DON'T MERGE] compare GLM-5.1 and GLM-5 chat_template
Browse files- chat_template.jinja +20 -51
chat_template.jinja
CHANGED
|
@@ -1,17 +1,5 @@
|
|
| 1 |
[gMASK]<sop>
|
| 2 |
{%- if tools -%}
|
| 3 |
-
{%- macro tool_to_json(tool) -%}
|
| 4 |
-
{%- set ns_tool = namespace(first=true) -%}
|
| 5 |
-
{{ '{' -}}
|
| 6 |
-
{%- for k, v in tool.items() -%}
|
| 7 |
-
{%- if k != 'defer_loading' and k != 'strict' -%}
|
| 8 |
-
{%- if not ns_tool.first -%}{{- ', ' -}}{%- endif -%}
|
| 9 |
-
{%- set ns_tool.first = false -%}
|
| 10 |
-
"{{ k }}": {{ v | tojson(ensure_ascii=False) }}
|
| 11 |
-
{%- endif -%}
|
| 12 |
-
{%- endfor -%}
|
| 13 |
-
{{- '}' -}}
|
| 14 |
-
{%- endmacro -%}
|
| 15 |
<|system|>
|
| 16 |
# Tools
|
| 17 |
|
|
@@ -20,12 +8,7 @@ You may call one or more functions to assist with the user query.
|
|
| 20 |
You are provided with function signatures within <tools></tools> XML tags:
|
| 21 |
<tools>
|
| 22 |
{% for tool in tools %}
|
| 23 |
-
{
|
| 24 |
-
{%- set tool = tool['function'] -%}
|
| 25 |
-
{%- endif -%}
|
| 26 |
-
{% if tool.defer_loading is not defined or not tool.defer_loading %}
|
| 27 |
-
{{ tool_to_json(tool) }}
|
| 28 |
-
{% endif %}
|
| 29 |
{% endfor %}
|
| 30 |
</tools>
|
| 31 |
|
|
@@ -46,34 +29,28 @@ For each function call, output the function name and arguments within the follow
|
|
| 46 |
{{- content }}
|
| 47 |
{%- endif -%}
|
| 48 |
{%- endmacro -%}
|
| 49 |
-
{%- set ns = namespace(last_user_index=-1
|
| 50 |
{%- for m in messages %}
|
| 51 |
{%- if m.role == 'user' %}
|
| 52 |
-
{%
|
| 53 |
-
{%- elif m.role == 'assistant' %}
|
| 54 |
-
{%- if m.reasoning_content is string %}
|
| 55 |
-
{%- set ns.thinking_indices = ns.thinking_indices ~ ',' ~ ns.last_user_index ~ ',' -%}
|
| 56 |
-
{%- endif %}
|
| 57 |
{%- endif %}
|
| 58 |
{%- endfor %}
|
| 59 |
-
{%
|
| 60 |
-
{%-
|
| 61 |
-
{%- if m.role == 'user' -%}<|user|>{{ visible_text(m.content) }}{% set ns.has_thinking = (',' ~ loop.index0 ~ ',') in ns.thinking_indices -%}
|
| 62 |
{%- elif m.role == 'assistant' -%}
|
| 63 |
<|assistant|>
|
|
|
|
| 64 |
{%- set content = visible_text(m.content) %}
|
| 65 |
{%- if m.reasoning_content is string %}
|
| 66 |
{%- set reasoning_content = m.reasoning_content %}
|
| 67 |
-
{%-
|
| 68 |
-
{%-
|
| 69 |
-
|
| 70 |
-
{%-
|
| 71 |
-
{%-
|
| 72 |
-
{%- elif loop.index0 < ns.last_user_index and ns.has_thinking %}
|
| 73 |
-
{%- set reasoning_content = '' %}
|
| 74 |
{%- endif %}
|
| 75 |
-
{%- if ((clear_thinking is defined and not clear_thinking) or loop.index0 > ns.last_user_index) and reasoning_content
|
| 76 |
-
{{ '<think>' + reasoning_content + '</think>'}}
|
| 77 |
{%- else -%}
|
| 78 |
{{ '</think>' }}
|
| 79 |
{%- endif -%}
|
|
@@ -89,24 +66,16 @@ For each function call, output the function name and arguments within the follow
|
|
| 89 |
{% set _args = tc.arguments %}{% for k, v in _args.items() %}<arg_key>{{ k }}</arg_key><arg_value>{{ v | tojson(ensure_ascii=False) if v is not string else v }}</arg_value>{% endfor %}</tool_call>{% endfor %}
|
| 90 |
{% endif %}
|
| 91 |
{%- elif m.role == 'tool' -%}
|
|
|
|
| 92 |
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
| 93 |
-
{{- '<|observation|>'
|
| 94 |
{%- endif %}
|
| 95 |
-
{
|
| 96 |
-
|
|
|
|
| 97 |
{%- else -%}
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
{%- for tool in tools -%}
|
| 101 |
-
{%- if 'function' in tool -%}
|
| 102 |
-
{%- set tool = tool['function'] -%}
|
| 103 |
-
{%- endif -%}
|
| 104 |
-
{%- if tool.name == tr.name -%}
|
| 105 |
-
{{- tool_to_json(tool) + '\n' -}}
|
| 106 |
-
{%- endif -%}
|
| 107 |
-
{%- endfor -%}
|
| 108 |
-
{%- endfor -%}
|
| 109 |
-
{{- '</tools></tool_response>' -}}
|
| 110 |
{% endif -%}
|
| 111 |
{%- elif m.role == 'system' -%}
|
| 112 |
<|system|>{{ visible_text(m.content) }}
|
|
|
|
| 1 |
[gMASK]<sop>
|
| 2 |
{%- if tools -%}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
<|system|>
|
| 4 |
# Tools
|
| 5 |
|
|
|
|
| 8 |
You are provided with function signatures within <tools></tools> XML tags:
|
| 9 |
<tools>
|
| 10 |
{% for tool in tools %}
|
| 11 |
+
{{ tool | tojson(ensure_ascii=False) }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
{% endfor %}
|
| 13 |
</tools>
|
| 14 |
|
|
|
|
| 29 |
{{- content }}
|
| 30 |
{%- endif -%}
|
| 31 |
{%- endmacro -%}
|
| 32 |
+
{%- set ns = namespace(last_user_index=-1) %}
|
| 33 |
{%- for m in messages %}
|
| 34 |
{%- if m.role == 'user' %}
|
| 35 |
+
{% set ns.last_user_index = loop.index0 -%}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
{%- endif %}
|
| 37 |
{%- endfor %}
|
| 38 |
+
{% for m in messages %}
|
| 39 |
+
{%- if m.role == 'user' -%}<|user|>{{ visible_text(m.content) }}
|
|
|
|
| 40 |
{%- elif m.role == 'assistant' -%}
|
| 41 |
<|assistant|>
|
| 42 |
+
{%- set reasoning_content = '' %}
|
| 43 |
{%- set content = visible_text(m.content) %}
|
| 44 |
{%- if m.reasoning_content is string %}
|
| 45 |
{%- set reasoning_content = m.reasoning_content %}
|
| 46 |
+
{%- else %}
|
| 47 |
+
{%- if '</think>' in content %}
|
| 48 |
+
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
|
| 49 |
+
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
| 50 |
+
{%- endif %}
|
|
|
|
|
|
|
| 51 |
{%- endif %}
|
| 52 |
+
{%- if ((clear_thinking is defined and not clear_thinking) or loop.index0 > ns.last_user_index) and reasoning_content -%}
|
| 53 |
+
{{ '<think>' + reasoning_content.strip() + '</think>'}}
|
| 54 |
{%- else -%}
|
| 55 |
{{ '</think>' }}
|
| 56 |
{%- endif -%}
|
|
|
|
| 66 |
{% set _args = tc.arguments %}{% for k, v in _args.items() %}<arg_key>{{ k }}</arg_key><arg_value>{{ v | tojson(ensure_ascii=False) if v is not string else v }}</arg_value>{% endfor %}</tool_call>{% endfor %}
|
| 67 |
{% endif %}
|
| 68 |
{%- elif m.role == 'tool' -%}
|
| 69 |
+
{%- if m.content is string -%}
|
| 70 |
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
| 71 |
+
{{- '<|observation|>' }}
|
| 72 |
{%- endif %}
|
| 73 |
+
{{- '<tool_response>' }}
|
| 74 |
+
{{- m.content }}
|
| 75 |
+
{{- '</tool_response>' }}
|
| 76 |
{%- else -%}
|
| 77 |
+
<|observation|>{% for tr in m.content %}
|
| 78 |
+
<tool_response>{{ tr.output if tr.output is defined else tr }}</tool_response>{% endfor -%}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
{% endif -%}
|
| 80 |
{%- elif m.role == 'system' -%}
|
| 81 |
<|system|>{{ visible_text(m.content) }}
|