mrtoots commited on
Commit
9de31d4
·
verified ·
1 Parent(s): b799edb

Upload chat_template.jinja with huggingface_hub

Browse files
Files changed (1) hide show
  1. chat_template.jinja +23 -14
chat_template.jinja CHANGED
@@ -1,4 +1,4 @@
1
- [gMASK]<sop>
2
  {%- if tools -%}
3
  <|system|>
4
  # Tools
@@ -8,7 +8,7 @@ You may call one or more functions to assist with the user query.
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
 
@@ -43,19 +43,25 @@ For each function call, output the function name and arguments within the follow
43
  {%- endfor %}
44
  {% for m in messages %}
45
  {%- if m.role == 'user' -%}<|user|>
46
- {{ visible_text(m.content) }}
47
- {{- '/nothink' if (enable_thinking is defined and not enable_thinking and not visible_text(m.content).endswith("/nothink")) else '' -}}
48
  {%- elif m.role == 'assistant' -%}
49
  <|assistant|>
50
  {%- set reasoning_content = '' %}
51
- {%- set content = visible_text(m.content) %}
52
- {%- if m.reasoning_content is string %}
53
  {%- set reasoning_content = m.reasoning_content %}
54
  {%- else %}
55
- {%- if '</think>' in content %}
56
- {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
57
- {%- set content = content.split('</think>')[-1].lstrip('\n') %}
58
- {%- endif %}
 
 
 
 
 
 
59
  {%- endif %}
60
  {%- if loop.index0 > ns.last_user_index and reasoning_content -%}
61
  {{ '\n<think>' + reasoning_content.strip() + '</think>'}}
@@ -72,9 +78,12 @@ For each function call, output the function name and arguments within the follow
72
  {%- endif %}
73
  {{ '\n<tool_call>' + tc.name }}
74
  {% set _args = tc.arguments %}
75
- {% for k, v in _args.items() %}
 
 
 
76
  <arg_key>{{ k }}</arg_key>
77
- <arg_value>{{ v | tojson(ensure_ascii=False) if v is not string else v }}</arg_value>
78
  {% endfor %}
79
  </tool_call>{% endfor %}
80
  {% endif %}
@@ -95,9 +104,9 @@ For each function call, output the function name and arguments within the follow
95
  {% endif -%}
96
  {%- elif m.role == 'system' -%}
97
  <|system|>
98
- {{ visible_text(m.content) }}
99
  {%- endif -%}
100
  {%- endfor -%}
101
  {%- if add_generation_prompt -%}
102
  <|assistant|>{{- '\n<think></think>' if (enable_thinking is defined and not enable_thinking) else '' -}}
103
- {%- endif -%}
 
1
+ {# Unsloth template fixes #}[gMASK]<sop>
2
  {%- if tools -%}
3
  <|system|>
4
  # Tools
 
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
 
 
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>'}}
 
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 %}
 
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. #}