MLX
jinja
chat-template
qwen
qwen3.5
qwen3.6
qwen3.8
llama.cpp
lm-studio
vllm
tool-calling
thinking
token-efficient
Instructions to use peculiar-ragdoll/Qwen-Sharp-Chat-Templates with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use peculiar-ragdoll/Qwen-Sharp-Chat-Templates with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] huggingface-cli download --local-dir Qwen-Sharp-Chat-Templates peculiar-ragdoll/Qwen-Sharp-Chat-Templates
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
Sharp v22: suppress forced-xhigh reasoning default (opt-in preserved via chat_template_kwargs); archive v1; card: shipped-models point to v1, add 'Setting reasoning effort' section
Browse files- README.md +66 -12
- chat_template.jinja +66 -61
- chat_template_oneline.txt +2 -48
- scripts/verify_template.py +20 -4
README.md
CHANGED
|
@@ -8,6 +8,7 @@ tags:
|
|
| 8 |
- qwen
|
| 9 |
- qwen3.5
|
| 10 |
- qwen3.6
|
|
|
|
| 11 |
- mlx
|
| 12 |
- llama.cpp
|
| 13 |
- lm-studio
|
|
@@ -20,17 +21,35 @@ tags:
|
|
| 20 |
# Qwen-Sharp-Chat-Templates
|
| 21 |
|
| 22 |
froggeric's [Qwen-Fixed-Chat-Templates](https://huggingface.co/froggeric/Qwen-Fixed-Chat-Templates)
|
| 23 |
-
`
|
| 24 |
-
drops into any Qwen3.5 or
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
## What it changes
|
| 32 |
|
| 33 |
-
|
| 34 |
|
| 35 |
```jinja
|
| 36 |
{%- set _terse %}
|
|
@@ -44,10 +63,15 @@ If a user request is genuinely ambiguous, ask a sharp question, don't guess.
|
|
| 44 |
{%- else %}
|
| 45 |
{%- set _sc = (_sc | trim) ~ '\n\n' ~ (_terse | trim) %}
|
| 46 |
{%- endif %}
|
|
|
|
|
|
|
|
|
|
| 47 |
```
|
| 48 |
|
| 49 |
-
|
| 50 |
-
after it
|
|
|
|
|
|
|
| 51 |
|
| 52 |
## What it does, measured
|
| 53 |
|
|
@@ -167,6 +191,36 @@ That case — a fresh `.jinja` dropped in next to a stale embedded copy — is t
|
|
| 167 |
this silently does nothing. It also warns if the template names a specific model, which happens
|
| 168 |
when the file was taken from a model repo rather than from here.
|
| 169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
## What it doesn't do
|
| 171 |
|
| 172 |
- **It is not a fine-tune**, despite the `base_model_relation: finetune` tag — that is the closest
|
|
@@ -177,8 +231,8 @@ when the file was taken from a model repo rather than from here.
|
|
| 177 |
the brevity and not the retention.
|
| 178 |
- **It is not tuned per model.** Every model responds a little differently to a terseness
|
| 179 |
instruction; measure yours. The numbers above are from a 27B; a 4B may need firmer wording.
|
| 180 |
-
- **The benchmarks are Qwen3.6.** The template covers 3.5 and 3.
|
| 181 |
-
into one file
|
| 182 |
|
| 183 |
## Credits
|
| 184 |
|
|
|
|
| 8 |
- qwen
|
| 9 |
- qwen3.5
|
| 10 |
- qwen3.6
|
| 11 |
+
- qwen3.8
|
| 12 |
- mlx
|
| 13 |
- llama.cpp
|
| 14 |
- lm-studio
|
|
|
|
| 21 |
# Qwen-Sharp-Chat-Templates
|
| 22 |
|
| 23 |
froggeric's [Qwen-Fixed-Chat-Templates](https://huggingface.co/froggeric/Qwen-Fixed-Chat-Templates)
|
| 24 |
+
`v22`, with a terseness system prompt spliced in. Model-agnostic: it names no model, so it
|
| 25 |
+
drops into any Qwen3.5, 3.6, or 3.8 build without claiming to be something it isn't.
|
| 26 |
+
|
| 27 |
+
> **v22 (the Qwen 3.8 update).** Upstream now covers Qwen 3.8 alongside 3.5/3.6 and adds
|
| 28 |
+
> prompt-directed reasoning-effort steering (`xhigh`/`high`/`medium`/`low`), which upstream
|
| 29 |
+
> **defaults to `xhigh`** — it injects a "think at maximum effort" system line even when the
|
| 30 |
+
> caller asks for nothing. That default is a behavioral change from `v21.3`, so this Sharp build
|
| 31 |
+
> **suppresses it**: when no effort is requested you get the tuned terseness behavior and nothing
|
| 32 |
+
> else, exactly as v1. An *explicit* effort still passes straight through to upstream's machinery
|
| 33 |
+
> and renders — the feature survives, it just isn't forced on. Pass it via `chat_template_kwargs`
|
| 34 |
+
> (a bare top-level `reasoning_effort` field is dropped by OpenAI-style servers before the template
|
| 35 |
+
> sees it):
|
| 36 |
+
>
|
| 37 |
+
> ```json
|
| 38 |
+
> {"messages": [...], "chat_template_kwargs": {"reasoning_effort": "low"}}
|
| 39 |
+
> ```
|
| 40 |
+
|
| 41 |
+
[Dagger-Qwen3.6-27B](https://huggingface.co/peculiar-ragdoll/Dagger-Qwen3.6-27B-MLX) and
|
| 42 |
+
[Nail-Qwen3.6-35B-A3B](https://huggingface.co/peculiar-ragdoll/Nail-Qwen3.6-35B-A3B-MLX) shipped with
|
| 43 |
+
the **v1** template baked into their weights — that is the exact template embedded in those GGUF and
|
| 44 |
+
MLX builds (`template_version = "qwen3.6-froggeric-v21.3"`, terseness, no reasoning-effort steering),
|
| 45 |
+
and it lives here in [`archive/v1-qwen3.6-froggeric-v21.3/`](archive/v1-qwen3.6-froggeric-v21.3). The
|
| 46 |
+
`chat_template.jinja` at the root of this repo is the newer **v22** described above; drop it in to
|
| 47 |
+
move a model onto it. The template is published separately because it is the portable part — the
|
| 48 |
+
thing worth reusing is not tied to either model.
|
| 49 |
|
| 50 |
## What it changes
|
| 51 |
|
| 52 |
+
Fourteen inserted lines. Everything else is byte-identical to upstream v22.
|
| 53 |
|
| 54 |
```jinja
|
| 55 |
{%- set _terse %}
|
|
|
|
| 63 |
{%- else %}
|
| 64 |
{%- set _sc = (_sc | trim) ~ '\n\n' ~ (_terse | trim) %}
|
| 65 |
{%- endif %}
|
| 66 |
+
{%- if reasoning_effort is not defined %}
|
| 67 |
+
{%- set reasoning_instructions = '' %}
|
| 68 |
+
{%- endif %}
|
| 69 |
```
|
| 70 |
|
| 71 |
+
Two things happen here. The `if/else` keeps **your own system prompt** — the terseness block is
|
| 72 |
+
appended after it, nothing you pass in is replaced. The final `if` blanks upstream's
|
| 73 |
+
reasoning-effort line **only when the caller didn't ask for one**, so the forced-`xhigh` default is
|
| 74 |
+
gone but an explicit `reasoning_effort` still renders (see the v22 note above).
|
| 75 |
|
| 76 |
## What it does, measured
|
| 77 |
|
|
|
|
| 191 |
this silently does nothing. It also warns if the template names a specific model, which happens
|
| 192 |
when the file was taken from a model repo rather than from here.
|
| 193 |
|
| 194 |
+
## Setting reasoning effort
|
| 195 |
+
|
| 196 |
+
By default there is no reasoning-effort instruction — you get the tuned terseness behavior and
|
| 197 |
+
nothing else. To turn steering back on for a request, set `reasoning_effort` to `low`, `medium`,
|
| 198 |
+
`high`, or `xhigh`. **How you pass it depends on the runtime, and one obvious-looking channel does
|
| 199 |
+
not work:**
|
| 200 |
+
|
| 201 |
+
| How you pass it | oMLX | llama.cpp | transformers | Works? |
|
| 202 |
+
|---|:--:|:--:|:--:|:--:|
|
| 203 |
+
| `chat_template_kwargs: {"reasoning_effort": "low"}` (in the request body) | ✅ | ✅ | — | **yes — use this** |
|
| 204 |
+
| `apply_chat_template(..., reasoning_effort="low")` (Python) | — | — | ✅ | **yes** |
|
| 205 |
+
| top-level `reasoning_effort` field (the OpenAI API param) | ❌ | ❌ | — | **no** |
|
| 206 |
+
|
| 207 |
+
```json
|
| 208 |
+
{"messages": [...], "chat_template_kwargs": {"reasoning_effort": "low"}}
|
| 209 |
+
```
|
| 210 |
+
|
| 211 |
+
The last row is the trap. The OpenAI-style **top-level** `reasoning_effort` field is *consumed by
|
| 212 |
+
the server* (oMLX and llama.cpp both use it internally to pick reasoning-parse behavior for formats
|
| 213 |
+
like harmony/gpt-oss) and is **never handed to the chat template** — so a custom Qwen template can't
|
| 214 |
+
see it, and it silently has no effect here. This isn't something the template can fix: a template
|
| 215 |
+
only reads the variables the runtime binds at render time. If you need the literal top-level field
|
| 216 |
+
to work against these servers, put a thin proxy in front that copies `reasoning_effort` into
|
| 217 |
+
`chat_template_kwargs` before forwarding. Otherwise, use the `chat_template_kwargs` channel above —
|
| 218 |
+
it works everywhere and needs no code.
|
| 219 |
+
|
| 220 |
+
Verified on both runtimes: with `chat_template_kwargs` the steering line renders (oMLX prompt grows
|
| 221 |
+
+38 tokens for `xhigh`, +26 for `low`; llama.cpp/minja `POST /apply-template` shows the same line);
|
| 222 |
+
with the bare top-level field it does not.
|
| 223 |
+
|
| 224 |
## What it doesn't do
|
| 225 |
|
| 226 |
- **It is not a fine-tune**, despite the `base_model_relation: finetune` tag — that is the closest
|
|
|
|
| 231 |
the brevity and not the retention.
|
| 232 |
- **It is not tuned per model.** Every model responds a little differently to a terseness
|
| 233 |
instruction; measure yours. The numbers above are from a 27B; a 4B may need firmer wording.
|
| 234 |
+
- **The benchmarks are Qwen3.6.** The template covers 3.5, 3.6, and 3.8 alike — upstream unified
|
| 235 |
+
them into one file — but every figure in the table was measured on a 3.6 model.
|
| 236 |
|
| 237 |
## Credits
|
| 238 |
|
chat_template.jinja
CHANGED
|
@@ -1,11 +1,17 @@
|
|
| 1 |
-
{%- set template_version = "qwen3.
|
| 2 |
{%- set _tool_format = tool_call_format if tool_call_format is defined else 'xml' %}
|
| 3 |
{%- set image_count = namespace(value=0) %}
|
| 4 |
{%- set video_count = namespace(value=0) %}
|
| 5 |
{%- set add_vision_id = add_vision_id if add_vision_id is defined else false %}
|
| 6 |
{%- set enable_thinking = enable_thinking if enable_thinking is defined else true %}
|
| 7 |
{%- set auto_disable_thinking_with_tools = auto_disable_thinking_with_tools if auto_disable_thinking_with_tools is defined else false %}
|
| 8 |
-
{%-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
{%- set max_tool_arg_chars = max_tool_arg_chars if max_tool_arg_chars is defined else 0 %}
|
| 10 |
{%- set max_tool_response_chars = max_tool_response_chars if max_tool_response_chars is defined else 0 %}
|
| 11 |
{%- set _has_tools = (tools is defined and tools and tools is iterable and tools is not mapping) %}
|
|
@@ -13,6 +19,45 @@
|
|
| 13 |
{%- if auto_disable_thinking_with_tools and _has_tools %}
|
| 14 |
{%- set ns_state.thinking = false %}
|
| 15 |
{%- endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
{%- macro render_content(content, do_vision_count, is_system_content=false) %}
|
| 17 |
{%- if content is string %}
|
| 18 |
{{- content }}
|
|
@@ -71,10 +116,8 @@
|
|
| 71 |
{%- if _sys_msg is not none %}
|
| 72 |
{%- set _sc = render_content(_sys_msg.content, false, true) | trim %}
|
| 73 |
{%- if '<|think_off|>' in _sc %}
|
| 74 |
-
{%- set ns_state.thinking = false %}
|
| 75 |
{%- set _sc = _sc.split('<|think_off|>') | join('') | trim %}
|
| 76 |
{%- elif '<|think_on|>' in _sc %}
|
| 77 |
-
{%- set ns_state.thinking = true %}
|
| 78 |
{%- set _sc = _sc.split('<|think_on|>') | join('') | trim %}
|
| 79 |
{%- endif %}
|
| 80 |
{%- endif %}
|
|
@@ -89,69 +132,34 @@ If a user request is genuinely ambiguous, ask a sharp question, don't guess.
|
|
| 89 |
{%- else %}
|
| 90 |
{%- set _sc = (_sc | trim) ~ '\n\n' ~ (_terse | trim) %}
|
| 91 |
{%- endif %}
|
|
|
|
|
|
|
|
|
|
| 92 |
{%- if _has_tools %}
|
| 93 |
{{- '<|im_start|>system\n' }}
|
|
|
|
|
|
|
|
|
|
| 94 |
{{- '# Tools\n\nYou have access to the following functions:\n\n<tools>' }}
|
| 95 |
{%- for tool in tools %}
|
| 96 |
{{- '\n' }}
|
| 97 |
{{- tool | tojson }}
|
| 98 |
{%- endfor %}
|
| 99 |
{{- '\n</tools>' }}
|
| 100 |
-
{%-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
{
|
| 104 |
-
|
| 105 |
-
Brief explanation of tool call
|
| 106 |
-
</think>
|
| 107 |
-
<tool_call>
|
| 108 |
-
{"name": "example_function_name", "arguments": {"example_parameter_1": "value_1", "example_parameter_2": "This is the value for the second parameter"}}
|
| 109 |
-
</tool_call>
|
| 110 |
-
{%- else %}
|
| 111 |
-
<think>
|
| 112 |
-
Brief explanation of tool call
|
| 113 |
-
</think>
|
| 114 |
-
<tool_call>
|
| 115 |
-
<function=example_function_name>
|
| 116 |
-
<parameter=example_parameter_1>
|
| 117 |
-
value_1
|
| 118 |
-
</parameter>
|
| 119 |
-
<parameter=example_parameter_2>
|
| 120 |
-
This is the value for the second parameter
|
| 121 |
-
that can span
|
| 122 |
-
multiple lines
|
| 123 |
-
</parameter>
|
| 124 |
-
</function>
|
| 125 |
-
</tool_call>
|
| 126 |
-
{%- endif %}
|
| 127 |
-
|
| 128 |
-
<IMPORTANT>
|
| 129 |
-
Reminder:
|
| 130 |
-
- You can use the <think></think> block to plan your next tool call OR to synthesize data and formulate your final response to the user.
|
| 131 |
-
- ALL explanation and reasoning MUST be placed strictly inside the <think></think> block.
|
| 132 |
-
{%- if _tool_format == 'json' %}
|
| 133 |
-
- Function calls MUST follow the specified format: a single JSON object with "name" and "arguments" keys inside <tool_call></tool_call> XML tags.
|
| 134 |
-
{%- else %}
|
| 135 |
-
- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags.
|
| 136 |
-
{%- endif %}
|
| 137 |
-
- If you choose to call a tool, you MUST output the <tool_call> block IMMEDIATELY after thinking, with NO conversational text before it.
|
| 138 |
-
{%- if _tool_format == 'json' %}
|
| 139 |
-
- The <tool_call> tag MUST be at the very beginning of a new line, with NO spaces or indentation before it.
|
| 140 |
-
{%- else %}
|
| 141 |
-
- The <tool_call> and <function> tags MUST be at the very beginning of a new line, with NO spaces or indentation before them.
|
| 142 |
-
{%- endif %}
|
| 143 |
-
- To call multiple functions, output a separate, completely closed <tool_call></tool_call> block for EACH function. Do NOT nest <tool_call> blocks.
|
| 144 |
-
- If you have all necessary data, provide your final answer directly to the user without any tool call.
|
| 145 |
-
</IMPORTANT>
|
| 146 |
-
{%- endset %}
|
| 147 |
-
{{- '\n\n' ~ tool_instructions | trim }}
|
| 148 |
{%- if _sc %}
|
| 149 |
{{- '\n\n' + _sc }}
|
| 150 |
{%- endif %}
|
| 151 |
{{- '<|im_end|>\n' }}
|
| 152 |
{%- else %}
|
| 153 |
{%- if _sc %}
|
| 154 |
-
{{- '<|im_start|>system\n' + _sc + '<|im_end|>\n' }}
|
|
|
|
|
|
|
| 155 |
{%- endif %}
|
| 156 |
{%- endif %}
|
| 157 |
{%- set _last_idx = _msgs | length - 1 %}
|
|
@@ -179,10 +187,8 @@ Reminder:
|
|
| 179 |
{%- set content = render_content(message.content, true, is_system) | trim %}
|
| 180 |
{%- if is_system or message.role == 'user' %}
|
| 181 |
{%- if '<|think_off|>' in content %}
|
| 182 |
-
{%- set ns_state.thinking = false %}
|
| 183 |
{%- set content = content.split('<|think_off|>') | join('') | trim %}
|
| 184 |
{%- elif '<|think_on|>' in content %}
|
| 185 |
-
{%- set ns_state.thinking = true %}
|
| 186 |
{%- set content = content.split('<|think_on|>') | join('') | trim %}
|
| 187 |
{%- endif %}
|
| 188 |
{%- endif %}
|
|
@@ -246,6 +252,7 @@ Reminder:
|
|
| 246 |
{%- else %}
|
| 247 |
{%- set tc = tool_call %}
|
| 248 |
{%- endif %}
|
|
|
|
| 249 |
{%- if _tool_format == 'json' %}
|
| 250 |
{%- if not loop.first or content | trim %}
|
| 251 |
{{- '\n\n' }}
|
|
@@ -258,16 +265,16 @@ Reminder:
|
|
| 258 |
{%- set _args = tc.arguments %}
|
| 259 |
{%- endif %}
|
| 260 |
{%- endif %}
|
| 261 |
-
{{- '<tool_call>\n{"name": ' }}{{-
|
| 262 |
{%- else %}
|
| 263 |
{%- if loop.first %}
|
| 264 |
{%- if content | trim %}
|
| 265 |
-
{{- '\n\n<tool_call>\n<function=' +
|
| 266 |
{%- else %}
|
| 267 |
-
{{- '<tool_call>\n<function=' +
|
| 268 |
{%- endif %}
|
| 269 |
{%- else %}
|
| 270 |
-
{{- '\n\n<tool_call>\n<function=' +
|
| 271 |
{%- endif %}
|
| 272 |
{%- if tc.arguments is defined and tc.arguments is not none %}
|
| 273 |
{%- if tc.arguments is mapping %}
|
|
@@ -332,8 +339,6 @@ Reminder:
|
|
| 332 |
{{- '<|im_start|>assistant\n' }}
|
| 333 |
{%- if not ns_state.thinking %}
|
| 334 |
{{- '<think>\n\n</think>\n\n' }}
|
| 335 |
-
{%- elif ns2.consecutive_failures >= 2 %}
|
| 336 |
-
{{- '<think>\n\n</think>\n\n' }}
|
| 337 |
{%- else %}
|
| 338 |
{{- '<think>\n' }}
|
| 339 |
{%- endif %}
|
|
|
|
| 1 |
+
{%- set template_version = "qwen3.8-froggeric-v22" %}
|
| 2 |
{%- set _tool_format = tool_call_format if tool_call_format is defined else 'xml' %}
|
| 3 |
{%- set image_count = namespace(value=0) %}
|
| 4 |
{%- set video_count = namespace(value=0) %}
|
| 5 |
{%- set add_vision_id = add_vision_id if add_vision_id is defined else false %}
|
| 6 |
{%- set enable_thinking = enable_thinking if enable_thinking is defined else true %}
|
| 7 |
{%- set auto_disable_thinking_with_tools = auto_disable_thinking_with_tools if auto_disable_thinking_with_tools is defined else false %}
|
| 8 |
+
{%- if preserve_reasoning is defined and preserve_reasoning is not none %}
|
| 9 |
+
{%- set _preserve_thinking = preserve_reasoning %}
|
| 10 |
+
{%- elif preserve_thinking is defined and preserve_thinking is not none %}
|
| 11 |
+
{%- set _preserve_thinking = preserve_thinking %}
|
| 12 |
+
{%- else %}
|
| 13 |
+
{%- set _preserve_thinking = true %}
|
| 14 |
+
{%- endif %}
|
| 15 |
{%- set max_tool_arg_chars = max_tool_arg_chars if max_tool_arg_chars is defined else 0 %}
|
| 16 |
{%- set max_tool_response_chars = max_tool_response_chars if max_tool_response_chars is defined else 0 %}
|
| 17 |
{%- set _has_tools = (tools is defined and tools and tools is iterable and tools is not mapping) %}
|
|
|
|
| 19 |
{%- if auto_disable_thinking_with_tools and _has_tools %}
|
| 20 |
{%- set ns_state.thinking = false %}
|
| 21 |
{%- endif %}
|
| 22 |
+
{%- for msg in messages %}
|
| 23 |
+
{%- if msg.role == 'system' or msg.role == 'developer' or msg.role == 'user' %}
|
| 24 |
+
{%- if msg.content is string %}
|
| 25 |
+
{%- if '<|think_off|>' in msg.content %}
|
| 26 |
+
{%- set ns_state.thinking = false %}
|
| 27 |
+
{%- elif '<|think_on|>' in msg.content %}
|
| 28 |
+
{%- set ns_state.thinking = true %}
|
| 29 |
+
{%- endif %}
|
| 30 |
+
{%- elif msg.content is iterable and msg.content is not mapping %}
|
| 31 |
+
{%- for item in msg.content %}
|
| 32 |
+
{%- if item is mapping and 'text' in item and item.text is string %}
|
| 33 |
+
{%- if '<|think_off|>' in item.text %}
|
| 34 |
+
{%- set ns_state.thinking = false %}
|
| 35 |
+
{%- elif '<|think_on|>' in item.text %}
|
| 36 |
+
{%- set ns_state.thinking = true %}
|
| 37 |
+
{%- endif %}
|
| 38 |
+
{%- endif %}
|
| 39 |
+
{%- endfor %}
|
| 40 |
+
{%- endif %}
|
| 41 |
+
{%- endif %}
|
| 42 |
+
{%- endfor %}
|
| 43 |
+
{%- set _effort_raw = reasoning_effort if reasoning_effort is defined else 'xhigh' %}
|
| 44 |
+
{%- if _effort_raw == 'high' or _effort_raw == 'xhigh' %}
|
| 45 |
+
{%- set _reasoning_effort = 'xhigh' %}
|
| 46 |
+
{%- elif _effort_raw == 'low' %}
|
| 47 |
+
{%- set _reasoning_effort = 'low' %}
|
| 48 |
+
{%- elif _effort_raw == 'medium' %}
|
| 49 |
+
{%- set _reasoning_effort = 'medium' %}
|
| 50 |
+
{%- else %}
|
| 51 |
+
{%- set _reasoning_effort = 'xhigh' %}
|
| 52 |
+
{%- endif %}
|
| 53 |
+
{%- set reasoning_instructions = '' %}
|
| 54 |
+
{%- if ns_state.thinking %}
|
| 55 |
+
{%- if _reasoning_effort == 'xhigh' %}
|
| 56 |
+
{%- set reasoning_instructions = 'Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.' %}
|
| 57 |
+
{%- elif _reasoning_effort == 'low' %}
|
| 58 |
+
{%- set reasoning_instructions = 'Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.' %}
|
| 59 |
+
{%- endif %}
|
| 60 |
+
{%- endif %}
|
| 61 |
{%- macro render_content(content, do_vision_count, is_system_content=false) %}
|
| 62 |
{%- if content is string %}
|
| 63 |
{{- content }}
|
|
|
|
| 116 |
{%- if _sys_msg is not none %}
|
| 117 |
{%- set _sc = render_content(_sys_msg.content, false, true) | trim %}
|
| 118 |
{%- if '<|think_off|>' in _sc %}
|
|
|
|
| 119 |
{%- set _sc = _sc.split('<|think_off|>') | join('') | trim %}
|
| 120 |
{%- elif '<|think_on|>' in _sc %}
|
|
|
|
| 121 |
{%- set _sc = _sc.split('<|think_on|>') | join('') | trim %}
|
| 122 |
{%- endif %}
|
| 123 |
{%- endif %}
|
|
|
|
| 132 |
{%- else %}
|
| 133 |
{%- set _sc = (_sc | trim) ~ '\n\n' ~ (_terse | trim) %}
|
| 134 |
{%- endif %}
|
| 135 |
+
{%- if reasoning_effort is not defined %}
|
| 136 |
+
{%- set reasoning_instructions = '' %}
|
| 137 |
+
{%- endif %}
|
| 138 |
{%- if _has_tools %}
|
| 139 |
{{- '<|im_start|>system\n' }}
|
| 140 |
+
{%- if reasoning_instructions %}
|
| 141 |
+
{{- reasoning_instructions + '\n\n' }}
|
| 142 |
+
{%- endif %}
|
| 143 |
{{- '# Tools\n\nYou have access to the following functions:\n\n<tools>' }}
|
| 144 |
{%- for tool in tools %}
|
| 145 |
{{- '\n' }}
|
| 146 |
{{- tool | tojson }}
|
| 147 |
{%- endfor %}
|
| 148 |
{{- '\n</tools>' }}
|
| 149 |
+
{%- if _tool_format == 'json' %}
|
| 150 |
+
{{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<think>\nBrief explanation of tool call\n</think>\n<tool_call>\n{"name": "example_function_name", "arguments": {"example_parameter_1": "value_1", "example_parameter_2": "This is the value for the second parameter"}}\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- You can use the <think></think> block to plan your next tool call OR to synthesize data and formulate your final response to the user.\n- ALL explanation and reasoning MUST be placed strictly inside the <think></think> block.\n- Function calls MUST follow the specified format: a single JSON object with "name" and "arguments" keys inside <tool_call></tool_call> XML tags.\n- If you choose to call a tool, you MUST output the <tool_call> block IMMEDIATELY after thinking, with NO conversational text before it.\n- The <tool_call> tag MUST be at the very beginning of a new line, with NO spaces or indentation before it.\n- To call multiple functions, output a separate, completely closed <tool_call></tool_call> block for EACH function. Do NOT nest <tool_call> blocks.\n- If you have all necessary data, provide your final answer directly to the user without any tool call.\n</IMPORTANT>' }}
|
| 151 |
+
{%- else %}
|
| 152 |
+
{{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<think>\nBrief explanation of tool call\n</think>\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- You can use the <think></think> block to plan your next tool call OR to synthesize data and formulate your final response to the user.\n- ALL explanation and reasoning MUST be placed strictly inside the <think></think> block.\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags.\n- If you choose to call a tool, you MUST output the <tool_call> block IMMEDIATELY after thinking, with NO conversational text before it.\n- The <tool_call> and <function> tags MUST be at the very beginning of a new line, with NO spaces or indentation before them.\n- To call multiple functions, output a separate, completely closed <tool_call></tool_call> block for EACH function. Do NOT nest <tool_call> blocks.\n- If you have all necessary data, provide your final answer directly to the user without any tool call.\n</IMPORTANT>' }}
|
| 153 |
+
{%- endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
{%- if _sc %}
|
| 155 |
{{- '\n\n' + _sc }}
|
| 156 |
{%- endif %}
|
| 157 |
{{- '<|im_end|>\n' }}
|
| 158 |
{%- else %}
|
| 159 |
{%- if _sc %}
|
| 160 |
+
{{- '<|im_start|>system\n' + (reasoning_instructions + '\n\n' if reasoning_instructions else '') + _sc + '<|im_end|>\n' }}
|
| 161 |
+
{%- elif reasoning_instructions %}
|
| 162 |
+
{{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
|
| 163 |
{%- endif %}
|
| 164 |
{%- endif %}
|
| 165 |
{%- set _last_idx = _msgs | length - 1 %}
|
|
|
|
| 187 |
{%- set content = render_content(message.content, true, is_system) | trim %}
|
| 188 |
{%- if is_system or message.role == 'user' %}
|
| 189 |
{%- if '<|think_off|>' in content %}
|
|
|
|
| 190 |
{%- set content = content.split('<|think_off|>') | join('') | trim %}
|
| 191 |
{%- elif '<|think_on|>' in content %}
|
|
|
|
| 192 |
{%- set content = content.split('<|think_on|>') | join('') | trim %}
|
| 193 |
{%- endif %}
|
| 194 |
{%- endif %}
|
|
|
|
| 252 |
{%- else %}
|
| 253 |
{%- set tc = tool_call %}
|
| 254 |
{%- endif %}
|
| 255 |
+
{%- set tc_name = tc.name if (tc.name is defined and tc.name is not none) else '' %}
|
| 256 |
{%- if _tool_format == 'json' %}
|
| 257 |
{%- if not loop.first or content | trim %}
|
| 258 |
{{- '\n\n' }}
|
|
|
|
| 265 |
{%- set _args = tc.arguments %}
|
| 266 |
{%- endif %}
|
| 267 |
{%- endif %}
|
| 268 |
+
{{- '<tool_call>\n{"name": ' }}{{- tc_name | tojson }}{{- ', "arguments": ' }}{{- _args }}{{- '}\n</tool_call>' }}
|
| 269 |
{%- else %}
|
| 270 |
{%- if loop.first %}
|
| 271 |
{%- if content | trim %}
|
| 272 |
+
{{- '\n\n<tool_call>\n<function=' + tc_name + '>\n' }}
|
| 273 |
{%- else %}
|
| 274 |
+
{{- '<tool_call>\n<function=' + tc_name + '>\n' }}
|
| 275 |
{%- endif %}
|
| 276 |
{%- else %}
|
| 277 |
+
{{- '\n\n<tool_call>\n<function=' + tc_name + '>\n' }}
|
| 278 |
{%- endif %}
|
| 279 |
{%- if tc.arguments is defined and tc.arguments is not none %}
|
| 280 |
{%- if tc.arguments is mapping %}
|
|
|
|
| 339 |
{{- '<|im_start|>assistant\n' }}
|
| 340 |
{%- if not ns_state.thinking %}
|
| 341 |
{{- '<think>\n\n</think>\n\n' }}
|
|
|
|
|
|
|
| 342 |
{%- else %}
|
| 343 |
{{- '<think>\n' }}
|
| 344 |
{%- endif %}
|
chat_template_oneline.txt
CHANGED
|
@@ -1,52 +1,6 @@
|
|
| 1 |
-
{%- set template_version = "qwen3.
|
| 2 |
Answer directly, after thinking. Lead with the answer, then only what it needs to be correct and usable.
|
| 3 |
Never: open with preamble or pleasantries; restate the question; add filler transitions; hedge with niceties; or repeat a point you've already made.
|
| 4 |
Always: keep essential steps, caveats, uncertainties, and specifics — never drop correctness or a needed warning for brevity. Keep the final answer lean. Use the least structure that conveys it (plain prose when short; lists or code only when they earn their place). If genuinely uncertain, say so and explain why — never omit uncertainty for the sake of brevity.
|
| 5 |
If a user request is genuinely ambiguous, ask a sharp question, don't guess.
|
| 6 |
-
{%- endset %} {%- if not _sc %}{%- set _sc = _terse | trim %}{%- else %}{%- set _sc = (_sc | trim) ~ '\n\n' ~ (_terse | trim) %}{%- endif %}{%- if _has_tools %}{{- '<|im_start|>system\n' }}{{- '# Tools\n\nYou have access to the following functions:\n\n<tools>' }}{%- for tool in tools %}{{- '\n' }}{{- tool | tojson }}{%- endfor %}{{- '\n</tools>' }} {%- set tool_instructions %}
|
| 7 |
-
If you choose to call a function ONLY reply in the following format with NO suffix:
|
| 8 |
-
|
| 9 |
-
{%- if _tool_format == 'json' %}
|
| 10 |
-
<think>
|
| 11 |
-
Brief explanation of tool call
|
| 12 |
-
</think>
|
| 13 |
-
<tool_call>
|
| 14 |
-
{"name": "example_function_name", "arguments": {"example_parameter_1": "value_1", "example_parameter_2": "This is the value for the second parameter"}}
|
| 15 |
-
</tool_call>
|
| 16 |
-
{%- else %}
|
| 17 |
-
<think>
|
| 18 |
-
Brief explanation of tool call
|
| 19 |
-
</think>
|
| 20 |
-
<tool_call>
|
| 21 |
-
<function=example_function_name>
|
| 22 |
-
<parameter=example_parameter_1>
|
| 23 |
-
value_1
|
| 24 |
-
</parameter>
|
| 25 |
-
<parameter=example_parameter_2>
|
| 26 |
-
This is the value for the second parameter
|
| 27 |
-
that can span
|
| 28 |
-
multiple lines
|
| 29 |
-
</parameter>
|
| 30 |
-
</function>
|
| 31 |
-
</tool_call>
|
| 32 |
-
{%- endif %}
|
| 33 |
-
|
| 34 |
-
<IMPORTANT>
|
| 35 |
-
Reminder:
|
| 36 |
-
- You can use the <think></think> block to plan your next tool call OR to synthesize data and formulate your final response to the user.
|
| 37 |
-
- ALL explanation and reasoning MUST be placed strictly inside the <think></think> block.
|
| 38 |
-
{%- if _tool_format == 'json' %}
|
| 39 |
-
- Function calls MUST follow the specified format: a single JSON object with "name" and "arguments" keys inside <tool_call></tool_call> XML tags.
|
| 40 |
-
{%- else %}
|
| 41 |
-
- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags.
|
| 42 |
-
{%- endif %}
|
| 43 |
-
- If you choose to call a tool, you MUST output the <tool_call> block IMMEDIATELY after thinking, with NO conversational text before it.
|
| 44 |
-
{%- if _tool_format == 'json' %}
|
| 45 |
-
- The <tool_call> tag MUST be at the very beginning of a new line, with NO spaces or indentation before it.
|
| 46 |
-
{%- else %}
|
| 47 |
-
- The <tool_call> and <function> tags MUST be at the very beginning of a new line, with NO spaces or indentation before them.
|
| 48 |
-
{%- endif %}
|
| 49 |
-
- To call multiple functions, output a separate, completely closed <tool_call></tool_call> block for EACH function. Do NOT nest <tool_call> blocks.
|
| 50 |
-
- If you have all necessary data, provide your final answer directly to the user without any tool call.
|
| 51 |
-
</IMPORTANT>
|
| 52 |
-
{%- endset %} {{- '\n\n' ~ tool_instructions | trim }}{%- if _sc %}{{- '\n\n' + _sc }}{%- endif %}{{- '<|im_end|>\n' }}{%- else %}{%- if _sc %}{{- '<|im_start|>system\n' + _sc + '<|im_end|>\n' }}{%- endif %}{%- endif %}{%- set _last_idx = _msgs | length - 1 %}{%- set ns = namespace(multi_step_tool=true, last_query_index=_last_idx) %}{%- for message in _msgs[::-1] %}{%- set index = (_msgs | length - 1) - loop.index0 %}{%- if ns.multi_step_tool and message.role == 'user' %}{%- set _rc = render_content(message.content, false) | trim %}{%- if not (_rc.startswith('<tool_response>') and _rc.endswith('</tool_response>')) %}{%- set ns.multi_step_tool = false %}{%- set ns.last_query_index = index %}{%- endif %}{%- endif %}{%- endfor %}{%- if ns.multi_step_tool %}{%- if _last_idx > 50 %}{%- set ns.last_query_index = _last_idx %}{%- else %}{%- set ns.last_query_index = 0 %}{%- endif %}{%- endif %}{%- set ns2 = namespace(prev_role='', consecutive_failures=0) %}{%- for message in _msgs %}{%- set is_system = (message.role == "system" or message.role == "developer") %}{%- set content = render_content(message.content, true, is_system) | trim %}{%- if is_system or message.role == 'user' %}{%- if '<|think_off|>' in content %}{%- set ns_state.thinking = false %}{%- set content = content.split('<|think_off|>') | join('') | trim %}{%- elif '<|think_on|>' in content %}{%- set ns_state.thinking = true %}{%- set content = content.split('<|think_on|>') | join('') | trim %}{%- endif %}{%- endif %}{%- if is_system %}{{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}{%- elif message.role == 'user' %}{%- set ns2.consecutive_failures = 0 %}{{- '<|im_start|>user\n' + content + '<|im_end|>\n' }}{%- elif message.role == 'assistant' %}{%- set reasoning_content = '' %}{%- if message.reasoning_content is defined and message.reasoning_content is not none %}{%- if message.reasoning_content is string %}{%- set reasoning_content = message.reasoning_content %}{%- else %}{%- set reasoning_content = message.reasoning_content | string %}{%- endif %}{%- elif message.thinking is defined and message.thinking is not none %}{%- if message.thinking is string %}{%- set reasoning_content = message.thinking %}{%- else %}{%- set reasoning_content = message.thinking | string %}{%- endif %}{%- else %}{%- set _think_end = '' %}{%- if content.startswith('</think>') %}{%- set _think_end = '</think>' %}{%- elif content.startswith('</thinking>') %}{%- set _think_end = '</thinking>' %}{%- elif '\n</think>' in content %}{%- set _think_end = '\n</think>' %}{%- elif '\n</thinking>' in content %}{%- set _think_end = '\n</thinking>' %}{%- elif '\n</ think>' in content %}{%- set _think_end = '\n</ think>' %}{%- elif '\n</think >' in content %}{%- set _think_end = '\n</think >' %}{%- endif %}{%- if _think_end %}{%- if 'thinking' in _think_end %}{%- set _think_start = '<thinking>' %}{%- else %}{%- set _think_start = '<think>' %}{%- endif %}{%- set reasoning_content = content.split(_think_end)[0].rstrip('\n') %}{%- if _think_start in reasoning_content %}{%- set reasoning_content = reasoning_content.split(_think_start)[-1].lstrip('\n') %}{%- endif %}{%- set content = content.split(_think_end)[-1].lstrip('\n') %}{%- endif %}{%- endif %}{%- set reasoning_content = reasoning_content | trim %}{%- if (_preserve_thinking or loop.index0 > ns.last_query_index) and reasoning_content %}{{- '<|im_start|>assistant\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}{%- else %}{{- '<|im_start|>assistant\n' + content }}{%- endif %}{%- if message.tool_calls is defined and message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}{%- for tool_call in message.tool_calls %}{%- if tool_call.function is defined and tool_call.function is not none %}{%- set tc = tool_call.function %}{%- else %}{%- set tc = tool_call %}{%- endif %}{%- if _tool_format == 'json' %}{%- if not loop.first or content | trim %}{{- '\n\n' }}{%- endif %}{%- set _args = '{}' %}{%- if tc.arguments is defined and tc.arguments is not none %}{%- if tc.arguments is mapping %}{%- set _args = tc.arguments | tojson %}{%- elif tc.arguments is string and tc.arguments %}{%- set _args = tc.arguments %}{%- endif %}{%- endif %}{{- '<tool_call>\n{"name": ' }}{{- tc.name | tojson }}{{- ', "arguments": ' }}{{- _args }}{{- '}\n</tool_call>' }}{%- else %}{%- if loop.first %}{%- if content | trim %}{{- '\n\n<tool_call>\n<function=' + tc.name + '>\n' }}{%- else %}{{- '<tool_call>\n<function=' + tc.name + '>\n' }}{%- endif %}{%- else %}{{- '\n\n<tool_call>\n<function=' + tc.name + '>\n' }}{%- endif %}{%- if tc.arguments is defined and tc.arguments is not none %}{%- if tc.arguments is mapping %}{%- for args_name, args_value in tc.arguments.items() %}{{- '<parameter=' + args_name + '>\n' }}{%- if args_value is mapping or (args_value is sequence and args_value is not string) %}{%- set _av = args_value | tojson %}{%- else %}{%- set _av = args_value | string %}{%- endif %}{%- if max_tool_arg_chars > 0 and _av | length > max_tool_arg_chars %}{{- _av[:max_tool_arg_chars] + '\n[TRUNCATED — original length ' ~ (_av | length | string) ~ ' chars]' }}{%- else %}{{- _av }}{%- endif %}{{- '\n</parameter>\n' }}{%- endfor %}{%- elif tc.arguments is string and tc.arguments %}{{- tc.arguments }}{%- endif %}{%- endif %}{{- '</function>\n</tool_call>' }}{%- endif %}{%- endfor %}{%- endif %}{{- '<|im_end|>\n' }}{%- elif message.role == 'tool' %}{%- set _content_lower = content | lower %}{%- set _content_head = _content_lower[:80] %}{%- if content | length < 500 and '$ ' not in content and 'took ' not in _content_lower and ('"error":' in _content_head or 'error:' in _content_head or 'err!' in _content_head or 'fatal:' in _content_head or 'exception:' in _content_head or 'traceback' in _content_head or 'command not found' in _content_head or 'invalid syntax' in _content_head or 'failed to' in _content_head) %}{%- set ns2.consecutive_failures = ns2.consecutive_failures + 1 %}{%- else %}{%- set ns2.consecutive_failures = 0 %}{%- endif %}{%- if ns2.prev_role != 'tool' %}{{- '<|im_start|>user' }}{%- endif %}{%- if max_tool_response_chars > 0 and content | length > max_tool_response_chars %}{%- set content = content[:max_tool_response_chars] + '\n[TRUNCATED — original length ' ~ (content | length | string) ~ ' chars]' %}{%- endif %}{{- '\n<tool_response>\n' + content }}{%- if ns2.consecutive_failures >= 2 %}{{- '\n\n⚠️ SYSTEM WARNING: ' ~ ns2.consecutive_failures ~ ' consecutive tool errors detected. Your previous approach is incorrect. You MUST use a fundamentally different approach or corrected arguments.' }}{%- elif ns2.consecutive_failures == 1 %}{{- '\n\n⚠️ SYSTEM WARNING: The previous tool call returned an error. Diagnose the failure and retry with completely corrected arguments.' }}{%- endif %}{{- '\n</tool_response>' }}{%- if loop.last %}{{- '<|im_end|>\n' }}{%- else %}{%- set _next_role = _msgs[loop.index0 + 1].role %}{%- if _next_role != 'tool' %}{{- '<|im_end|>\n' }}{%- endif %}{%- endif %}{%- else %}{{- '<|im_start|>user\n[' + message.role + ']: ' + content + '<|im_end|>\n' }}{%- endif %}{%- set ns2.prev_role = message.role %}{%- endfor %}{%- if add_generation_prompt %}{{- '<|im_start|>assistant\n' }}{%- if not ns_state.thinking %}{{- '<think>\n\n</think>\n\n' }}{%- elif ns2.consecutive_failures >= 2 %}{{- '<think>\n\n</think>\n\n' }}{%- else %}{{- '<think>\n' }}{%- endif %}{%- endif %}
|
|
|
|
| 1 |
+
{%- set template_version = "qwen3.8-froggeric-v22" %}{%- set _tool_format = tool_call_format if tool_call_format is defined else 'xml' %}{%- set image_count = namespace(value=0) %}{%- set video_count = namespace(value=0) %}{%- set add_vision_id = add_vision_id if add_vision_id is defined else false %}{%- set enable_thinking = enable_thinking if enable_thinking is defined else true %}{%- set auto_disable_thinking_with_tools = auto_disable_thinking_with_tools if auto_disable_thinking_with_tools is defined else false %}{%- if preserve_reasoning is defined and preserve_reasoning is not none %}{%- set _preserve_thinking = preserve_reasoning %}{%- elif preserve_thinking is defined and preserve_thinking is not none %}{%- set _preserve_thinking = preserve_thinking %}{%- else %}{%- set _preserve_thinking = true %}{%- endif %}{%- set max_tool_arg_chars = max_tool_arg_chars if max_tool_arg_chars is defined else 0 %}{%- set max_tool_response_chars = max_tool_response_chars if max_tool_response_chars is defined else 0 %}{%- set _has_tools = (tools is defined and tools and tools is iterable and tools is not mapping) %}{%- set ns_state = namespace(thinking=enable_thinking) %}{%- if auto_disable_thinking_with_tools and _has_tools %}{%- set ns_state.thinking = false %}{%- endif %}{%- for msg in messages %}{%- if msg.role == 'system' or msg.role == 'developer' or msg.role == 'user' %}{%- if msg.content is string %}{%- if '<|think_off|>' in msg.content %}{%- set ns_state.thinking = false %}{%- elif '<|think_on|>' in msg.content %}{%- set ns_state.thinking = true %}{%- endif %}{%- elif msg.content is iterable and msg.content is not mapping %}{%- for item in msg.content %}{%- if item is mapping and 'text' in item and item.text is string %}{%- if '<|think_off|>' in item.text %}{%- set ns_state.thinking = false %}{%- elif '<|think_on|>' in item.text %}{%- set ns_state.thinking = true %}{%- endif %}{%- endif %}{%- endfor %}{%- endif %}{%- endif %}{%- endfor %}{%- set _effort_raw = reasoning_effort if reasoning_effort is defined else 'xhigh' %}{%- if _effort_raw == 'high' or _effort_raw == 'xhigh' %}{%- set _reasoning_effort = 'xhigh' %}{%- elif _effort_raw == 'low' %}{%- set _reasoning_effort = 'low' %}{%- elif _effort_raw == 'medium' %}{%- set _reasoning_effort = 'medium' %}{%- else %}{%- set _reasoning_effort = 'xhigh' %}{%- endif %}{%- set reasoning_instructions = '' %}{%- if ns_state.thinking %}{%- if _reasoning_effort == 'xhigh' %}{%- set reasoning_instructions = 'Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.' %}{%- elif _reasoning_effort == 'low' %}{%- set reasoning_instructions = 'Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.' %}{%- endif %}{%- endif %}{%- macro render_content(content, do_vision_count, is_system_content=false) %}{%- if content is string %}{{- content }}{%- elif content is iterable and content is not mapping %}{%- for item in content %}{%- if item is mapping %}{%- if item.type == 'image' or 'image' in item or 'image_url' in item %}{%- if is_system_content %}{{- raise_exception('System message cannot contain images.') }}{%- endif %}{%- if do_vision_count %}{%- set image_count.value = image_count.value + 1 %}{%- endif %}{%- if add_vision_id %}{{- 'Picture ' ~ image_count.value ~ ': ' }}{%- endif %}{{- '<|vision_start|><|image_pad|><|vision_end|>' }}{%- elif item.type == 'video' or 'video' in item %}{%- if is_system_content %}{{- raise_exception('System message cannot contain videos.') }}{%- endif %}{%- if do_vision_count %}{%- set video_count.value = video_count.value + 1 %}{%- endif %}{%- if add_vision_id %}{{- 'Video ' ~ video_count.value ~ ': ' }}{%- endif %}{{- '<|vision_start|><|video_pad|><|vision_end|>' }}{%- elif 'text' in item %}{{- item.text }}{%- else %}{{- raise_exception('Unexpected item type in content.') }}{%- endif %}{%- else %}{{- item | string }}{%- endif %}{%- endfor %}{%- elif content is none or content is undefined %}{{- '' }}{%- else %}{{- raise_exception('Unexpected content type.') }}{%- endif %}{%- endmacro %}{%- if not messages %}{{- raise_exception('No messages provided.') }}{%- endif %}{%- set _first_role = messages[0].role %}{%- if _first_role == 'system' or _first_role == 'developer' %}{%- set _sys_msg = messages[0] %}{%- set _msgs = messages[1:] %}{%- else %}{%- set _sys_msg = none %}{%- set _msgs = messages %}{%- endif %}{%- set _sc = '' %}{%- if _sys_msg is not none %}{%- set _sc = render_content(_sys_msg.content, false, true) | trim %}{%- if '<|think_off|>' in _sc %}{%- set _sc = _sc.split('<|think_off|>') | join('') | trim %}{%- elif '<|think_on|>' in _sc %}{%- set _sc = _sc.split('<|think_on|>') | join('') | trim %}{%- endif %}{%- endif %} {%- set _terse %}
|
| 2 |
Answer directly, after thinking. Lead with the answer, then only what it needs to be correct and usable.
|
| 3 |
Never: open with preamble or pleasantries; restate the question; add filler transitions; hedge with niceties; or repeat a point you've already made.
|
| 4 |
Always: keep essential steps, caveats, uncertainties, and specifics — never drop correctness or a needed warning for brevity. Keep the final answer lean. Use the least structure that conveys it (plain prose when short; lists or code only when they earn their place). If genuinely uncertain, say so and explain why — never omit uncertainty for the sake of brevity.
|
| 5 |
If a user request is genuinely ambiguous, ask a sharp question, don't guess.
|
| 6 |
+
{%- endset %} {%- if not _sc %}{%- set _sc = _terse | trim %}{%- else %}{%- set _sc = (_sc | trim) ~ '\n\n' ~ (_terse | trim) %}{%- endif %}{%- if reasoning_effort is not defined %}{%- set reasoning_instructions = '' %}{%- endif %}{%- if _has_tools %}{{- '<|im_start|>system\n' }}{%- if reasoning_instructions %}{{- reasoning_instructions + '\n\n' }}{%- endif %}{{- '# Tools\n\nYou have access to the following functions:\n\n<tools>' }}{%- for tool in tools %}{{- '\n' }}{{- tool | tojson }}{%- endfor %}{{- '\n</tools>' }}{%- if _tool_format == 'json' %}{{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<think>\nBrief explanation of tool call\n</think>\n<tool_call>\n{"name": "example_function_name", "arguments": {"example_parameter_1": "value_1", "example_parameter_2": "This is the value for the second parameter"}}\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- You can use the <think></think> block to plan your next tool call OR to synthesize data and formulate your final response to the user.\n- ALL explanation and reasoning MUST be placed strictly inside the <think></think> block.\n- Function calls MUST follow the specified format: a single JSON object with "name" and "arguments" keys inside <tool_call></tool_call> XML tags.\n- If you choose to call a tool, you MUST output the <tool_call> block IMMEDIATELY after thinking, with NO conversational text before it.\n- The <tool_call> tag MUST be at the very beginning of a new line, with NO spaces or indentation before it.\n- To call multiple functions, output a separate, completely closed <tool_call></tool_call> block for EACH function. Do NOT nest <tool_call> blocks.\n- If you have all necessary data, provide your final answer directly to the user without any tool call.\n</IMPORTANT>' }}{%- else %}{{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<think>\nBrief explanation of tool call\n</think>\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- You can use the <think></think> block to plan your next tool call OR to synthesize data and formulate your final response to the user.\n- ALL explanation and reasoning MUST be placed strictly inside the <think></think> block.\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags.\n- If you choose to call a tool, you MUST output the <tool_call> block IMMEDIATELY after thinking, with NO conversational text before it.\n- The <tool_call> and <function> tags MUST be at the very beginning of a new line, with NO spaces or indentation before them.\n- To call multiple functions, output a separate, completely closed <tool_call></tool_call> block for EACH function. Do NOT nest <tool_call> blocks.\n- If you have all necessary data, provide your final answer directly to the user without any tool call.\n</IMPORTANT>' }}{%- endif %}{%- if _sc %}{{- '\n\n' + _sc }}{%- endif %}{{- '<|im_end|>\n' }}{%- else %}{%- if _sc %}{{- '<|im_start|>system\n' + (reasoning_instructions + '\n\n' if reasoning_instructions else '') + _sc + '<|im_end|>\n' }}{%- elif reasoning_instructions %}{{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}{%- endif %}{%- endif %}{%- set _last_idx = _msgs | length - 1 %}{%- set ns = namespace(multi_step_tool=true, last_query_index=_last_idx) %}{%- for message in _msgs[::-1] %}{%- set index = (_msgs | length - 1) - loop.index0 %}{%- if ns.multi_step_tool and message.role == 'user' %}{%- set _rc = render_content(message.content, false) | trim %}{%- if not (_rc.startswith('<tool_response>') and _rc.endswith('</tool_response>')) %}{%- set ns.multi_step_tool = false %}{%- set ns.last_query_index = index %}{%- endif %}{%- endif %}{%- endfor %}{%- if ns.multi_step_tool %}{%- if _last_idx > 50 %}{%- set ns.last_query_index = _last_idx %}{%- else %}{%- set ns.last_query_index = 0 %}{%- endif %}{%- endif %}{%- set ns2 = namespace(prev_role='', consecutive_failures=0) %}{%- for message in _msgs %}{%- set is_system = (message.role == "system" or message.role == "developer") %}{%- set content = render_content(message.content, true, is_system) | trim %}{%- if is_system or message.role == 'user' %}{%- if '<|think_off|>' in content %}{%- set content = content.split('<|think_off|>') | join('') | trim %}{%- elif '<|think_on|>' in content %}{%- set content = content.split('<|think_on|>') | join('') | trim %}{%- endif %}{%- endif %}{%- if is_system %}{{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}{%- elif message.role == 'user' %}{%- set ns2.consecutive_failures = 0 %}{{- '<|im_start|>user\n' + content + '<|im_end|>\n' }}{%- elif message.role == 'assistant' %}{%- set reasoning_content = '' %}{%- if message.reasoning_content is defined and message.reasoning_content is not none %}{%- if message.reasoning_content is string %}{%- set reasoning_content = message.reasoning_content %}{%- else %}{%- set reasoning_content = message.reasoning_content | string %}{%- endif %}{%- elif message.thinking is defined and message.thinking is not none %}{%- if message.thinking is string %}{%- set reasoning_content = message.thinking %}{%- else %}{%- set reasoning_content = message.thinking | string %}{%- endif %}{%- else %}{%- set _think_end = '' %}{%- if content.startswith('</think>') %}{%- set _think_end = '</think>' %}{%- elif content.startswith('</thinking>') %}{%- set _think_end = '</thinking>' %}{%- elif '\n</think>' in content %}{%- set _think_end = '\n</think>' %}{%- elif '\n</thinking>' in content %}{%- set _think_end = '\n</thinking>' %}{%- elif '\n</ think>' in content %}{%- set _think_end = '\n</ think>' %}{%- elif '\n</think >' in content %}{%- set _think_end = '\n</think >' %}{%- endif %}{%- if _think_end %}{%- if 'thinking' in _think_end %}{%- set _think_start = '<thinking>' %}{%- else %}{%- set _think_start = '<think>' %}{%- endif %}{%- set reasoning_content = content.split(_think_end)[0].rstrip('\n') %}{%- if _think_start in reasoning_content %}{%- set reasoning_content = reasoning_content.split(_think_start)[-1].lstrip('\n') %}{%- endif %}{%- set content = content.split(_think_end)[-1].lstrip('\n') %}{%- endif %}{%- endif %}{%- set reasoning_content = reasoning_content | trim %}{%- if (_preserve_thinking or loop.index0 > ns.last_query_index) and reasoning_content %}{{- '<|im_start|>assistant\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}{%- else %}{{- '<|im_start|>assistant\n' + content }}{%- endif %}{%- if message.tool_calls is defined and message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}{%- for tool_call in message.tool_calls %}{%- if tool_call.function is defined and tool_call.function is not none %}{%- set tc = tool_call.function %}{%- else %}{%- set tc = tool_call %}{%- endif %}{%- set tc_name = tc.name if (tc.name is defined and tc.name is not none) else '' %}{%- if _tool_format == 'json' %}{%- if not loop.first or content | trim %}{{- '\n\n' }}{%- endif %}{%- set _args = '{}' %}{%- if tc.arguments is defined and tc.arguments is not none %}{%- if tc.arguments is mapping %}{%- set _args = tc.arguments | tojson %}{%- elif tc.arguments is string and tc.arguments %}{%- set _args = tc.arguments %}{%- endif %}{%- endif %}{{- '<tool_call>\n{"name": ' }}{{- tc_name | tojson }}{{- ', "arguments": ' }}{{- _args }}{{- '}\n</tool_call>' }}{%- else %}{%- if loop.first %}{%- if content | trim %}{{- '\n\n<tool_call>\n<function=' + tc_name + '>\n' }}{%- else %}{{- '<tool_call>\n<function=' + tc_name + '>\n' }}{%- endif %}{%- else %}{{- '\n\n<tool_call>\n<function=' + tc_name + '>\n' }}{%- endif %}{%- if tc.arguments is defined and tc.arguments is not none %}{%- if tc.arguments is mapping %}{%- for args_name, args_value in tc.arguments.items() %}{{- '<parameter=' + args_name + '>\n' }}{%- if args_value is mapping or (args_value is sequence and args_value is not string) %}{%- set _av = args_value | tojson %}{%- else %}{%- set _av = args_value | string %}{%- endif %}{%- if max_tool_arg_chars > 0 and _av | length > max_tool_arg_chars %}{{- _av[:max_tool_arg_chars] + '\n[TRUNCATED — original length ' ~ (_av | length | string) ~ ' chars]' }}{%- else %}{{- _av }}{%- endif %}{{- '\n</parameter>\n' }}{%- endfor %}{%- elif tc.arguments is string and tc.arguments %}{{- tc.arguments }}{%- endif %}{%- endif %}{{- '</function>\n</tool_call>' }}{%- endif %}{%- endfor %}{%- endif %}{{- '<|im_end|>\n' }}{%- elif message.role == 'tool' %}{%- set _content_lower = content | lower %}{%- set _content_head = _content_lower[:80] %}{%- if content | length < 500 and '$ ' not in content and 'took ' not in _content_lower and ('"error":' in _content_head or 'error:' in _content_head or 'err!' in _content_head or 'fatal:' in _content_head or 'exception:' in _content_head or 'traceback' in _content_head or 'command not found' in _content_head or 'invalid syntax' in _content_head or 'failed to' in _content_head) %}{%- set ns2.consecutive_failures = ns2.consecutive_failures + 1 %}{%- else %}{%- set ns2.consecutive_failures = 0 %}{%- endif %}{%- if ns2.prev_role != 'tool' %}{{- '<|im_start|>user' }}{%- endif %}{%- if max_tool_response_chars > 0 and content | length > max_tool_response_chars %}{%- set content = content[:max_tool_response_chars] + '\n[TRUNCATED — original length ' ~ (content | length | string) ~ ' chars]' %}{%- endif %}{{- '\n<tool_response>\n' + content }}{%- if ns2.consecutive_failures >= 2 %}{{- '\n\n⚠️ SYSTEM WARNING: ' ~ ns2.consecutive_failures ~ ' consecutive tool errors detected. Your previous approach is incorrect. You MUST use a fundamentally different approach or corrected arguments.' }}{%- elif ns2.consecutive_failures == 1 %}{{- '\n\n⚠️ SYSTEM WARNING: The previous tool call returned an error. Diagnose the failure and retry with completely corrected arguments.' }}{%- endif %}{{- '\n</tool_response>' }}{%- if loop.last %}{{- '<|im_end|>\n' }}{%- else %}{%- set _next_role = _msgs[loop.index0 + 1].role %}{%- if _next_role != 'tool' %}{{- '<|im_end|>\n' }}{%- endif %}{%- endif %}{%- else %}{{- '<|im_start|>user\n[' + message.role + ']: ' + content + '<|im_end|>\n' }}{%- endif %}{%- set ns2.prev_role = message.role %}{%- endfor %}{%- if add_generation_prompt %}{{- '<|im_start|>assistant\n' }}{%- if not ns_state.thinking %}{{- '<think>\n\n</think>\n\n' }}{%- else %}{{- '<think>\n' }}{%- endif %}{%- endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scripts/verify_template.py
CHANGED
|
@@ -46,14 +46,14 @@ def main() -> int:
|
|
| 46 |
full = (HERE / "chat_template.jinja").read_text()
|
| 47 |
mini = (HERE / "chat_template_oneline.txt").read_text()
|
| 48 |
|
| 49 |
-
print("=== diff vs upstream
|
| 50 |
with urllib.request.urlopen(UPSTREAM, timeout=60) as r:
|
| 51 |
up = r.read().decode()
|
| 52 |
diff = [l for l in difflib.unified_diff(up.splitlines(), full.splitlines(), lineterm="")
|
| 53 |
if l.startswith(("+", "-")) and not l.startswith(("+++", "---"))]
|
| 54 |
check(all(l.startswith("+") for l in diff), "only insertions, no upstream lines changed")
|
| 55 |
-
check(len(diff) ==
|
| 56 |
-
check('template_version = "qwen3.
|
| 57 |
check("Nail" not in full and "Dagger" not in full, "no model-specific identity in template")
|
| 58 |
|
| 59 |
print("\n=== rendering")
|
|
@@ -73,6 +73,19 @@ def main() -> int:
|
|
| 73 |
check("<think>t</think>" in render(full, cases["multi-turn w/ think"]),
|
| 74 |
"prior thinking is retained across turns")
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
tools = [{"type": "function", "function": {"name": "get_weather", "description": "w",
|
| 77 |
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}}}}]
|
| 78 |
out = render(full, [{"role": "user", "content": "weather?"}], tools=tools)
|
|
@@ -83,7 +96,10 @@ def main() -> int:
|
|
| 83 |
check(render(full, msgs) == render(mini, msgs), f"{name}: oneline == full")
|
| 84 |
sysblk = render(mini, cases["no system prompt"]).split("<|im_start|>system")[1] \
|
| 85 |
.split("<|im_end|>")[0].strip()
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
print(f"\n{'ALL CHECKS PASSED' if not fails else str(len(fails)) + ' FAILED: ' + '; '.join(fails)}")
|
| 89 |
return 1 if fails else 0
|
|
|
|
| 46 |
full = (HERE / "chat_template.jinja").read_text()
|
| 47 |
mini = (HERE / "chat_template_oneline.txt").read_text()
|
| 48 |
|
| 49 |
+
print("=== diff vs upstream v22")
|
| 50 |
with urllib.request.urlopen(UPSTREAM, timeout=60) as r:
|
| 51 |
up = r.read().decode()
|
| 52 |
diff = [l for l in difflib.unified_diff(up.splitlines(), full.splitlines(), lineterm="")
|
| 53 |
if l.startswith(("+", "-")) and not l.startswith(("+++", "---"))]
|
| 54 |
check(all(l.startswith("+") for l in diff), "only insertions, no upstream lines changed")
|
| 55 |
+
check(len(diff) == 14, f"exactly 14 inserted lines (got {len(diff)})")
|
| 56 |
+
check('template_version = "qwen3.8-froggeric-v22"' in full, "upstream version is v22")
|
| 57 |
check("Nail" not in full and "Dagger" not in full, "no model-specific identity in template")
|
| 58 |
|
| 59 |
print("\n=== rendering")
|
|
|
|
| 73 |
check("<think>t</think>" in render(full, cases["multi-turn w/ think"]),
|
| 74 |
"prior thinking is retained across turns")
|
| 75 |
|
| 76 |
+
# v22 defaults reasoning_effort to xhigh and injects a steering line; our splice suppresses that
|
| 77 |
+
# default so out-of-the-box behavior matches tuned v1 (terseness-only) -- but an EXPLICIT effort
|
| 78 |
+
# is still honored, so froggeric's feature survives as opt-in.
|
| 79 |
+
STEER = "Reasoning effort is set to"
|
| 80 |
+
check(STEER not in render(full, cases["no system prompt"]),
|
| 81 |
+
"default (no reasoning_effort): xhigh steering is suppressed")
|
| 82 |
+
check(STEER not in render(full, cases["with system prompt"]),
|
| 83 |
+
"default with system prompt: steering still suppressed")
|
| 84 |
+
check("Reasoning effort is set to low" in render(full, cases["no system prompt"],
|
| 85 |
+
reasoning_effort="low"), "explicit reasoning_effort=low is still honored (opt-in)")
|
| 86 |
+
check(MARKER in render(full, cases["no system prompt"], reasoning_effort="low"),
|
| 87 |
+
"terseness still present when an explicit effort is requested")
|
| 88 |
+
|
| 89 |
tools = [{"type": "function", "function": {"name": "get_weather", "description": "w",
|
| 90 |
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}}}}]
|
| 91 |
out = render(full, [{"role": "user", "content": "weather?"}], tools=tools)
|
|
|
|
| 96 |
check(render(full, msgs) == render(mini, msgs), f"{name}: oneline == full")
|
| 97 |
sysblk = render(mini, cases["no system prompt"]).split("<|im_start|>system")[1] \
|
| 98 |
.split("<|im_end|>")[0].strip()
|
| 99 |
+
# v22 prepends reasoning-effort steering to the system block, so isolate the terseness tail
|
| 100 |
+
# (it starts with "Answer directly,") and confirm ITS newlines survived minification as 4 lines.
|
| 101 |
+
terse = "Answer directly," + sysblk.split("Answer directly,", 1)[1]
|
| 102 |
+
check(len(terse.splitlines()) == 4, "terseness survives minification as 4 lines")
|
| 103 |
|
| 104 |
print(f"\n{'ALL CHECKS PASSED' if not fails else str(len(fails)) + ' FAILED: ' + '; '.join(fails)}")
|
| 105 |
return 1 if fails else 0
|