turboderp commited on
Commit
69d5203
·
verified ·
1 Parent(s): 727376e

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. .gitattributes +0 -2
  2. chat_template.jinja +168 -0
.gitattributes CHANGED
@@ -34,5 +34,3 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  inference/examples/images/carrots.jpeg filter=lfs diff=lfs merge=lfs -text
37
- model.safetensors.index.json filter=lfs diff=lfs merge=lfs -text
38
- quantization_config.json filter=lfs diff=lfs merge=lfs -text
 
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  inference/examples/images/carrots.jpeg filter=lfs diff=lfs merge=lfs -text
 
 
chat_template.jinja ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {# DeepSeek-V4 Hugging Face chat template.
2
+
3
+ Extra apply_chat_template kwargs:
4
+ thinking_mode: "thinking" (default) or "chat"
5
+ enable_thinking: boolean alias for thinking_mode (default: true)
6
+ drop_thinking: true (default)
7
+ reasoning_effort: "low" (default), "high", or "max"
8
+
9
+ Historical tool-call arguments must be mappings, as expected by the HF chat
10
+ template API, rather than OpenAI wire-format JSON strings.
11
+
12
+ Parallel tool-result messages must be supplied in the same order as the
13
+ corresponding assistant tool_calls. Sandboxed Jinja cannot reorder them by
14
+ tool-call ID.
15
+ #}
16
+ {%- macro render_tools(tool_list) -%}
17
+ {{- '## Tools\n\nYou have access to a set of tools to help answer the user\'s question. You can invoke tools by writing a "<|DSML|tool_calls>" block like the following:\n\n<|DSML|tool_calls>\n<|DSML|invoke name="$TOOL_NAME">\n<|DSML|parameter name="$PARAMETER_NAME" string="true|false">$PARAMETER_VALUE</|DSML|parameter>\n...\n</|DSML|invoke>\n<|DSML|invoke name="$TOOL_NAME2">\n...\n</|DSML|invoke>\n</|DSML|tool_calls>\n\nString parameters should be specified as is and set `string="true"`. For all other types (numbers, booleans, arrays, objects), pass the value in JSON format and set `string="false"`.\n\nIf thinking_mode is enabled (triggered by <think>), you MUST output your complete reasoning inside <think>...</think> BEFORE any tool calls or final response.\n\nOtherwise, output directly after </think> with tool calls or final response.\n\n### Available Tool Schemas\n\n' -}}
18
+ {%- for tool in tool_list -%}
19
+ {%- if tool.function is defined -%}
20
+ {{- tool.function | tojson -}}
21
+ {%- else -%}
22
+ {{- tool | tojson -}}
23
+ {%- endif -%}
24
+ {{- '\n' -}}
25
+ {%- endfor -%}
26
+ {{- '\nYou MUST strictly follow the above defined tool name and parameter schemas to invoke tool calls.\n' -}}
27
+ {%- endmacro -%}
28
+
29
+ {%- macro render_content(content) -%}
30
+ {%- if content is string -%}
31
+ {{- content -}}
32
+ {%- elif content is iterable -%}
33
+ {%- for block in content -%}
34
+ {%- if not loop.first -%}{{- '\n\n' -}}{%- endif -%}
35
+ {%- if block.type == 'text' -%}
36
+ {{- block.text | default('') -}}
37
+ {%- elif block.type == 'tool_result' -%}
38
+ {{- '<tool_result>' -}}
39
+ {%- if block.content is string -%}
40
+ {{- block.content -}}
41
+ {%- else -%}
42
+ {%- for part in block.content -%}
43
+ {%- if not loop.first -%}{{- '\n\n' -}}{%- endif -%}
44
+ {%- if part.type == 'text' -%}{{- part.text | default('') -}}{%- else -%}{{- '[Unsupported ' ~ part.type ~ ']' -}}{%- endif -%}
45
+ {%- endfor -%}
46
+ {%- endif -%}
47
+ {{- '</tool_result>' -}}
48
+ {%- else -%}
49
+ {{- '[Unsupported ' ~ block.type ~ ']' -}}
50
+ {%- endif -%}
51
+ {%- endfor -%}
52
+ {%- endif -%}
53
+ {%- endmacro -%}
54
+
55
+ {%- macro assistant_leader(mode, should_think) -%}
56
+ {{- '<|Assistant|>' -}}
57
+ {%- if mode == 'thinking' and should_think -%}{{- '<think>' -}}{%- else -%}{{- '</think>' -}}{%- endif -%}
58
+ {%- endmacro -%}
59
+
60
+ {# An explicit thinking_mode wins when both spellings are provided. #}
61
+ {%- if thinking_mode is defined -%}
62
+ {%- set mode = thinking_mode -%}
63
+ {%- elif enable_thinking is defined -%}
64
+ {%- set mode = 'thinking' if enable_thinking else 'chat' -%}
65
+ {%- else -%}
66
+ {%- set mode = 'thinking' -%}
67
+ {%- endif -%}
68
+ {%- if mode not in ['chat', 'thinking'] -%}{{- raise_exception('thinking_mode must be "chat" or "thinking"') -}}{%- endif -%}
69
+ {%- set effort = reasoning_effort | default('low') -%}
70
+ {%- if effort not in ['low', 'high', 'max'] -%}{{- raise_exception('reasoning_effort must be "low", "high", or "max"') -}}{%- endif -%}
71
+ {%- set requested_drop = drop_thinking | default(true) -%}
72
+ {%- set state = namespace(has_tools=(tools is defined and tools), last_user=-1, tool_owner=-1) -%}
73
+ {%- for message in messages -%}
74
+ {%- if message.role in ['user', 'developer'] -%}{%- set state.last_user = loop.index0 -%}{%- endif -%}
75
+ {%- if message.tools is defined and message.tools -%}{%- set state.has_tools = true -%}{%- endif -%}
76
+ {%- endfor -%}
77
+ {%- if tools is defined and tools -%}
78
+ {%- for message in messages -%}
79
+ {%- if state.tool_owner == -1 and message.role == 'system' -%}{%- set state.tool_owner = loop.index0 -%}{%- endif -%}
80
+ {%- endfor -%}
81
+ {%- if state.tool_owner == -1 -%}
82
+ {%- for message in messages -%}
83
+ {%- if state.tool_owner == -1 and message.role in ['developer', 'user'] -%}{%- set state.tool_owner = loop.index0 -%}{%- endif -%}
84
+ {%- endfor -%}
85
+ {%- endif -%}
86
+ {%- endif -%}
87
+ {%- set effective_drop = requested_drop and not state.has_tools -%}
88
+
89
+ {{- '<|begin▁of▁sentence|>' -}}
90
+ {%- if mode == 'thinking' and effort == 'high' -%}
91
+ {{- 'Reasoning Effort: Absolute maximum with no shortcuts permitted.\nYou MUST be very thorough in your thinking and comprehensively decompose the problem to resolve the root cause, rigorously stress-testing your logic against all potential paths, edge cases, and adversarial scenarios.\nExplicitly write out your entire deliberation process, documenting every intermediate step, considered alternative, and rejected hypothesis to ensure absolutely no assumption is left unchecked.\n\n' -}}
92
+ {%- elif mode == 'thinking' and effort == 'max' -%}
93
+ {{- 'Reasoning Effort: Beyond maximum — exhaustive, relentless, and uncompromising.\nYou MUST reason with the utmost depth and rigor, leaving absolutely nothing to chance: exhaustively decompose the problem into its most fundamental components, trace every causal chain to its root, and resolve the underlying cause rather than any surface symptom.\nDo not stop reasoning until you have independently verified the solution from multiple angles and are certain that no assumption remains unchecked and no error remains undiscovered.\n\n' -}}
94
+ {%- endif -%}
95
+
96
+ {%- for message in messages -%}
97
+ {%- set idx = loop.index0 -%}
98
+ {%- set next_role = loop.nextitem.role if not loop.last else none -%}
99
+ {%- set prev_role = loop.previtem.role if not loop.first else none -%}
100
+ {%- set skip = effective_drop and mode == 'thinking' and message.role == 'developer' and idx < state.last_user -%}
101
+ {%- if not skip -%}
102
+ {%- if message.role == 'system' -%}
103
+ {{- message.content | default('', true) -}}
104
+ {%- set local_tools = message.tools if message.tools is defined and message.tools else (tools if tools is defined and tools and idx == state.tool_owner else none) -%}
105
+ {%- if local_tools -%}{{- '\n\n' ~ render_tools(local_tools) -}}{%- endif -%}
106
+ {%- if message.response_format is defined and message.response_format -%}{{- '\n\n## Response Format:\n\nYou MUST strictly adhere to the following schema to reply:\n' ~ (message.response_format | tojson) -}}{%- endif -%}
107
+
108
+ {%- elif message.role == 'latest_reminder' -%}
109
+ {{- '<|latest_reminder|>' ~ (message.content | default('', true)) -}}
110
+
111
+ {%- elif message.role in ['user', 'developer'] -%}
112
+ {{- '<|User|>' -}}
113
+ {%- if message.role == 'user' -%}{{- render_content(message.content | default('', true)) -}}{%- else -%}{{- message.content | default('', true) -}}{%- endif -%}
114
+ {%- set local_tools = message.tools if message.tools is defined and message.tools else (tools if tools is defined and tools and idx == state.tool_owner else none) -%}
115
+ {%- if local_tools -%}{{- '\n\n' ~ render_tools(local_tools) -}}{%- endif -%}
116
+ {%- if message.response_format is defined and message.response_format -%}{{- '\n\n## Response Format:\n\nYou MUST strictly adhere to the following schema to reply:\n' ~ (message.response_format | tojson) -}}{%- endif -%}
117
+ {%- if message.task is defined and message.task -%}
118
+ {%- if message.task == 'action' -%}
119
+ {{- assistant_leader(mode, mode == 'thinking') ~ '<|action|>' -}}
120
+ {%- elif message.task in ['query', 'authority', 'domain', 'title', 'read_url'] -%}
121
+ {{- '<|' ~ message.task ~ '|>' -}}
122
+ {%- else -%}
123
+ {{- raise_exception('Unsupported task: ' ~ message.task) -}}
124
+ {%- endif -%}
125
+ {%- elif next_role == 'assistant' or (loop.last and add_generation_prompt) -%}
126
+ {{- assistant_leader(mode, mode == 'thinking' and (not effective_drop or idx >= state.last_user)) -}}
127
+ {%- endif -%}
128
+
129
+ {%- elif message.role == 'tool' -%}
130
+ {%- if prev_role != 'tool' -%}{{- '<|User|>' -}}{%- else -%}{{- '\n\n' -}}{%- endif -%}
131
+ {{- '<tool_result>' -}}
132
+ {%- if message.content is string -%}{{- message.content -}}{%- else -%}{{- message.content | tojson -}}{%- endif -%}
133
+ {{- '</tool_result>' -}}
134
+ {%- if next_role != 'tool' and (next_role == 'assistant' or (loop.last and add_generation_prompt)) -%}
135
+ {{- assistant_leader(mode, mode == 'thinking' and (not effective_drop or idx >= state.last_user)) -}}
136
+ {%- endif -%}
137
+
138
+ {%- elif message.role == 'assistant' -%}
139
+ {%- set prev_has_task = not loop.first and loop.previtem.task is defined and loop.previtem.task -%}
140
+ {%- if mode == 'thinking' and not prev_has_task and (not effective_drop or idx > state.last_user) -%}
141
+ {{- message.reasoning_content | default('', true) ~ '</think>' -}}
142
+ {%- endif -%}
143
+ {{- message.content | default('', true) -}}
144
+ {%- if message.tool_calls is defined and message.tool_calls -%}
145
+ {{- '\n\n<|DSML|tool_calls>\n' -}}
146
+ {%- for call in message.tool_calls -%}
147
+ {%- set function = call.function if call.function is defined else call -%}
148
+ {{- '<|DSML|invoke name="' ~ function.name ~ '">\n' -}}
149
+ {%- if function.arguments is not mapping -%}
150
+ {{- raise_exception('Historical tool-call arguments must be a mapping, not a JSON string') -}}
151
+ {%- endif -%}
152
+ {%- for name, value in function.arguments.items() -%}
153
+ {{- '<|DSML|parameter name="' ~ name ~ '" string="' ~ ('true' if value is string else 'false') ~ '">' -}}
154
+ {{- value if value is string else (value | tojson) -}}
155
+ {{- '</|DSML|parameter>\n' -}}
156
+ {%- endfor -%}
157
+ {{- '</|DSML|invoke>' -}}
158
+ {%- if not loop.last -%}{{- '\n' -}}{%- endif -%}
159
+ {%- endfor -%}
160
+ {{- '\n</|DSML|tool_calls>' -}}
161
+ {%- endif -%}
162
+ {%- if not (message.wo_eos is defined and message.wo_eos) -%}{{- '<|end▁of▁sentence|>' -}}{%- endif -%}
163
+ {%- if message.task is defined and message.task == 'title' -%}{{- '<|title|>' -}}{%- endif -%}
164
+ {%- else -%}
165
+ {{- raise_exception('Unsupported role: ' ~ message.role) -}}
166
+ {%- endif -%}
167
+ {%- endif -%}
168
+ {%- endfor -%}