fix: `clear_thinking` inserts spurious `</think>` tag when reasoning_content is empty
#46
by beckyu - opened
- chat_template.jinja +9 -5
chat_template.jinja
CHANGED
|
@@ -49,11 +49,14 @@ For each function call, output the function name and arguments within the follow
|
|
| 49 |
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
| 50 |
{%- endif %}
|
| 51 |
{%- endif %}
|
| 52 |
-
{
|
| 53 |
-
{
|
| 54 |
-
{
|
| 55 |
-
{
|
|
|
|
|
|
|
| 56 |
{%- endif -%}
|
|
|
|
| 57 |
{%- if content.strip() -%}
|
| 58 |
{{ content.strip() }}
|
| 59 |
{%- endif -%}
|
|
@@ -83,4 +86,5 @@ For each function call, output the function name and arguments within the follow
|
|
| 83 |
{%- endfor -%}
|
| 84 |
{%- if add_generation_prompt -%}
|
| 85 |
<|assistant|>{{- '</think>' if (enable_thinking is defined and not enable_thinking) else '<think>' -}}
|
| 86 |
-
|
|
|
|
|
|
| 49 |
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
| 50 |
{%- endif %}
|
| 51 |
{%- endif %}
|
| 52 |
+
{#- FIXED: clear_thinking=true means clear thinking content, no thinking tags at all -#}
|
| 53 |
+
{%- if clear_thinking is not defined or not clear_thinking -%}
|
| 54 |
+
{#- clear_thinking=false or undefined: keep thinking content -#}
|
| 55 |
+
{%- if reasoning_content -%}
|
| 56 |
+
{{ '<think>' + reasoning_content.strip() + '</think>' }}
|
| 57 |
+
{%- endif -%}
|
| 58 |
{%- endif -%}
|
| 59 |
+
{#- clear_thinking=true: only output content, no thinking tags -#}
|
| 60 |
{%- if content.strip() -%}
|
| 61 |
{{ content.strip() }}
|
| 62 |
{%- endif -%}
|
|
|
|
| 86 |
{%- endfor -%}
|
| 87 |
{%- if add_generation_prompt -%}
|
| 88 |
<|assistant|>{{- '</think>' if (enable_thinking is defined and not enable_thinking) else '<think>' -}}
|
| 89 |
+
|
| 90 |
+
{%- endif -%}
|