mrtoots commited on
Commit
fcd947f
·
verified ·
1 Parent(s): f93f73c

Upload chat_template.jinja with huggingface_hub

Browse files
Files changed (1) hide show
  1. chat_template.jinja +112 -0
chat_template.jinja ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {# Unsloth template fixes #}[gMASK]<sop>
2
+ {%- if tools -%}
3
+ <|system|>
4
+ # Tools
5
+
6
+ You may call one or more functions to assist with the user query.
7
+
8
+ You are provided with function signatures within <tools></tools> XML tags:
9
+ <tools>
10
+ {% for tool in tools %}
11
+ {{ tool | tojson|string }}
12
+ {% endfor %}
13
+ </tools>
14
+
15
+ For each function call, output the function name and arguments within the following XML format:
16
+ <tool_call>{function-name}
17
+ <arg_key>{arg-key-1}</arg_key>
18
+ <arg_value>{arg-value-1}</arg_value>
19
+ <arg_key>{arg-key-2}</arg_key>
20
+ <arg_value>{arg-value-2}</arg_value>
21
+ ...
22
+ </tool_call>{%- endif -%}
23
+ {%- macro visible_text(content) -%}
24
+ {%- if content is string -%}
25
+ {{- content }}
26
+ {%- elif content is iterable and content is not mapping -%}
27
+ {%- for item in content -%}
28
+ {%- if item is mapping and item.type == 'text' -%}
29
+ {{- item.text }}
30
+ {%- elif item is string -%}
31
+ {{- item }}
32
+ {%- endif -%}
33
+ {%- endfor -%}
34
+ {%- else -%}
35
+ {{- content }}
36
+ {%- endif -%}
37
+ {%- endmacro -%}
38
+ {%- set ns = namespace(last_user_index=-1) %}
39
+ {%- for m in messages %}
40
+ {%- if m.role == 'user' %}
41
+ {% set ns.last_user_index = loop.index0 -%}
42
+ {%- endif %}
43
+ {%- endfor %}
44
+ {% for m in messages %}
45
+ {%- if m.role == 'user' -%}<|user|>
46
+ {%- set content = visible_text(m.content)|string %}{{ content }}
47
+ {{- '/nothink' if (enable_thinking is defined and not enable_thinking and not content.endswith("/nothink")) else '' -}}
48
+ {%- elif m.role == 'assistant' -%}
49
+ <|assistant|>
50
+ {%- set reasoning_content = '' %}
51
+ {%- set content = visible_text(m.content)|string %}
52
+ {%- if m.reasoning_content is defined and m.reasoning_content is string %}
53
+ {%- set reasoning_content = m.reasoning_content %}
54
+ {%- else %}
55
+ {# Unsloth template fixes - must change to for loop since llama.cpp will error out if not #}
56
+ {%- set parts = content.split('</think>') %}
57
+ {% for part in parts %}
58
+ {%- if loop.index0 == 0 -%}
59
+ {%- set reasoning_content = (part.split("<think>")|last) %}
60
+ {%- set reasoning_content = reasoning_content.lstrip('\n').rstrip('\n') -%}
61
+ {%- else -%}
62
+ {%- set content = part.lstrip('\n') %}
63
+ {%- endif %}
64
+ {%- endfor %}
65
+ {%- endif %}
66
+ {%- if loop.index0 > ns.last_user_index and reasoning_content -%}
67
+ {{ '\n<think>' + reasoning_content.strip() + '</think>'}}
68
+ {%- else -%}
69
+ {{ '\n<think></think>' }}
70
+ {%- endif -%}
71
+ {%- if content.strip() -%}
72
+ {{ '\n' + content.strip() }}
73
+ {%- endif -%}
74
+ {% if m.tool_calls %}
75
+ {% for tc in m.tool_calls %}
76
+ {%- if tc.function %}
77
+ {%- set tc = tc.function %}
78
+ {%- endif %}
79
+ {{ '\n<tool_call>' + tc.name }}
80
+ {% set _args = tc.arguments %}
81
+ {%- if _args is not mapping -%}
82
+ {%- set _args = {} %}
83
+ {%- endif -%}
84
+ {% for k, v in _args|items %}
85
+ <arg_key>{{ k }}</arg_key>
86
+ <arg_value>{{ v | tojson|string if v is not string else v }}</arg_value>
87
+ {% endfor %}
88
+ </tool_call>{% endfor %}
89
+ {% endif %}
90
+ {%- elif m.role == 'tool' -%}
91
+ {%- if m.content is string -%}
92
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
93
+ {{- '<|observation|>' }}
94
+ {%- endif %}
95
+ {{- '\n<tool_response>\n' }}
96
+ {{- m.content }}
97
+ {{- '\n</tool_response>' }}
98
+ {%- else -%}
99
+ <|observation|>{% for tr in m.content %}
100
+
101
+ <tool_response>
102
+ {{ tr.output if tr.output is defined else tr }}
103
+ </tool_response>{% endfor -%}
104
+ {% endif -%}
105
+ {%- elif m.role == 'system' -%}
106
+ <|system|>
107
+ {{ visible_text(m.content)|string }}
108
+ {%- endif -%}
109
+ {%- endfor -%}
110
+ {%- if add_generation_prompt -%}
111
+ <|assistant|>{{- '\n<think></think>' if (enable_thinking is defined and not enable_thinking) else '' -}}
112
+ {%- endif -%}{# Copyright 2025-present Unsloth. Apache 2.0 License. #}