CyberNative AI LLC commited on
Commit
cb16fdf
·
1 Parent(s): 314113f

Sync chat_template.jinja with the 16 October encoding.py changes

Browse files
Files changed (1) hide show
  1. chat_template.jinja +17 -3
chat_template.jinja CHANGED
@@ -1,4 +1,4 @@
1
- {#- DeepSeek-V4.1 chat template, ported from encoding/encoding.py in the model repo.
2
  Extra kwargs: thinking_mode ("thinking" | "chat", default "thinking"; enable_thinking=true/false is accepted
3
  as an alias), drop_thinking (default true), reasoning_effort (int in [1, 100] or "low"/"medium"/"high"/"max",
4
  default "high"). Assistant reasoning is read from reasoning_content, or from thinking as an alias. -#}
@@ -75,6 +75,11 @@
75
  {%- set mns = namespace(list=[]) -%}
76
  {%- for msg in messages -%}
77
  {%- set content = msg.get("content") -%}
 
 
 
 
 
78
  {%- set is_blocks = content is iterable and content is not string and content is not mapping -%}
79
  {%- if content is string and IMG in content -%}
80
  {{- raise_exception("Message content contains image special token " ~ IMG ~ ". Images should be provided as image content blocks.") -}}
@@ -151,10 +156,19 @@
151
  {%- endfor -%}
152
  {%- set msgs = sns.list -%}
153
 
154
- {#- Mid-conversation system messages count as user turns. Tools anywhere disable drop_thinking. -#}
 
155
  {%- set state = namespace(last_user=-1, has_tools=false) -%}
156
  {%- for m in msgs -%}
157
- {%- if m.role == "user" or (m.role == "system" and loop.index0 > 0) -%}{%- set state.last_user = loop.index0 -%}{%- endif -%}
 
 
 
 
 
 
 
 
158
  {%- if m.get("tools") -%}{%- set state.has_tools = true -%}{%- endif -%}
159
  {%- endfor -%}
160
  {%- set effective_drop = drop_thinking and not state.has_tools -%}
 
1
+ {#- DeepSeek-V4.1 chat template, ported from encoding/encoding.py in the model repo (synced with its 2026-10-16 revision).
2
  Extra kwargs: thinking_mode ("thinking" | "chat", default "thinking"; enable_thinking=true/false is accepted
3
  as an alias), drop_thinking (default true), reasoning_effort (int in [1, 100] or "low"/"medium"/"high"/"max",
4
  default "high"). Assistant reasoning is read from reasoning_content, or from thinking as an alias. -#}
 
75
  {%- set mns = namespace(list=[]) -%}
76
  {%- for msg in messages -%}
77
  {%- set content = msg.get("content") -%}
78
+ {%- if msg.role == "user" and msg.get("content_blocks") is not none -%}
79
+ {%- set content = msg.content_blocks -%}
80
+ {%- elif msg.role == "tool" and msg.get("content_blocks") and content is not string -%}
81
+ {%- set content = msg.content_blocks -%}
82
+ {%- endif -%}
83
  {%- set is_blocks = content is iterable and content is not string and content is not mapping -%}
84
  {%- if content is string and IMG in content -%}
85
  {{- raise_exception("Message content contains image special token " ~ IMG ~ ". Images should be provided as image content blocks.") -}}
 
156
  {%- endfor -%}
157
  {%- set msgs = sns.list -%}
158
 
159
+ {#- Mid-conversation system messages count as user turns; user messages holding only tool results do not.
160
+ Tools anywhere disable drop_thinking. -#}
161
  {%- set state = namespace(last_user=-1, has_tools=false) -%}
162
  {%- for m in msgs -%}
163
+ {%- set starts_turn = (m.role == "system" and loop.index0 > 0) -%}
164
+ {%- if m.role == "user" -%}
165
+ {%- set turn = namespace(found=not m.content_blocks) -%}
166
+ {%- for b in m.content_blocks or [] -%}
167
+ {%- if b.type in ["text", "image", "image_url"] -%}{%- set turn.found = true -%}{%- endif -%}
168
+ {%- endfor -%}
169
+ {%- set starts_turn = turn.found -%}
170
+ {%- endif -%}
171
+ {%- if starts_turn -%}{%- set state.last_user = loop.index0 -%}{%- endif -%}
172
  {%- if m.get("tools") -%}{%- set state.has_tools = true -%}{%- endif -%}
173
  {%- endfor -%}
174
  {%- set effective_drop = drop_thinking and not state.has_tools -%}