Fix double think tag when resuming think
Browse files- chat_template.jinja +25 -39
chat_template.jinja
CHANGED
|
@@ -21,19 +21,16 @@ For each function call, output the function name and arguments within the follow
|
|
| 21 |
...
|
| 22 |
</tool_call>
|
| 23 |
{%- endif -%}
|
| 24 |
-
|
| 25 |
{%- set ns = namespace(has_system=false) %}
|
| 26 |
-
{%- for
|
| 27 |
-
{%- if
|
| 28 |
{%- set ns.has_system = true %}
|
| 29 |
{%- endif %}
|
| 30 |
{%- endfor %}
|
| 31 |
-
|
| 32 |
{%- if not ns.has_system and not tools -%}
|
| 33 |
<|system|>
|
| 34 |
You are INTELLECT-3, a helpful assistant developed by Prime Intellect.
|
| 35 |
{%- endif -%}
|
| 36 |
-
|
| 37 |
{%- macro visible_text(content) -%}
|
| 38 |
{%- if content is string -%}
|
| 39 |
{{- content }}
|
|
@@ -49,42 +46,31 @@ You are INTELLECT-3, a helpful assistant developed by Prime Intellect.
|
|
| 49 |
{{- content }}
|
| 50 |
{%- endif -%}
|
| 51 |
{%- endmacro -%}
|
| 52 |
-
|
| 53 |
{%- set ns = namespace(last_user_index=-1) %}
|
| 54 |
-
{%- for
|
| 55 |
-
{%- if
|
| 56 |
{% set ns.last_user_index = loop.index0 -%}
|
| 57 |
{%- endif %}
|
| 58 |
{%- endfor %}
|
| 59 |
-
|
| 60 |
-
{
|
| 61 |
-
|
| 62 |
-
{%-
|
| 63 |
-
{{ visible_text(m.content) }}
|
| 64 |
-
|
| 65 |
-
{%- elif m.role == 'assistant' -%}
|
| 66 |
<|assistant|>
|
| 67 |
-
{%-
|
| 68 |
-
{%-
|
| 69 |
-
{
|
| 70 |
-
{%-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
{%- else %}
|
| 72 |
-
{
|
| 73 |
-
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
|
| 74 |
-
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
| 75 |
-
{%- endif %}
|
| 76 |
-
{%- endif %}
|
| 77 |
-
{%- if reasoning_content -%}
|
| 78 |
-
{{ '\n<think>' + reasoning_content.strip() + '</think>' }}
|
| 79 |
-
{%- else -%}
|
| 80 |
-
{{ '\n<think></think>' }}
|
| 81 |
-
{%- endif -%}
|
| 82 |
-
{%- if content.strip() -%}
|
| 83 |
-
{{ '\n' + content.strip() }}
|
| 84 |
{%- endif -%}
|
| 85 |
-
|
| 86 |
-
{%
|
| 87 |
-
{% for tc in m.tool_calls %}
|
| 88 |
{%- if tc.function %}
|
| 89 |
{%- set tc = tc.function %}
|
| 90 |
{%- endif %}
|
|
@@ -96,13 +82,13 @@ You are INTELLECT-3, a helpful assistant developed by Prime Intellect.
|
|
| 96 |
{% endfor %}
|
| 97 |
</tool_call>{% endfor %}
|
| 98 |
{% endif %}
|
| 99 |
-
{%- elif
|
| 100 |
-
{%- if
|
| 101 |
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
| 102 |
{{- '<|observation|>' }}
|
| 103 |
{%- endif %}
|
| 104 |
{{- '\n<tool_response>\n' }}
|
| 105 |
-
{{-
|
| 106 |
{{- '\n</tool_response>' }}
|
| 107 |
{%- else -%}
|
| 108 |
<|observation|>{% for tr in m.content %}
|
|
@@ -111,9 +97,9 @@ You are INTELLECT-3, a helpful assistant developed by Prime Intellect.
|
|
| 111 |
</tool_response>{% endfor -%}
|
| 112 |
{% endif -%}
|
| 113 |
|
| 114 |
-
{%- elif
|
| 115 |
<|system|>
|
| 116 |
-
{{ visible_text(
|
| 117 |
{%- endif -%}
|
| 118 |
|
| 119 |
{%- endfor -%}
|
|
|
|
| 21 |
...
|
| 22 |
</tool_call>
|
| 23 |
{%- endif -%}
|
|
|
|
| 24 |
{%- set ns = namespace(has_system=false) %}
|
| 25 |
+
{%- for message in messages %}
|
| 26 |
+
{%- if message.role == 'system' %}
|
| 27 |
{%- set ns.has_system = true %}
|
| 28 |
{%- endif %}
|
| 29 |
{%- endfor %}
|
|
|
|
| 30 |
{%- if not ns.has_system and not tools -%}
|
| 31 |
<|system|>
|
| 32 |
You are INTELLECT-3, a helpful assistant developed by Prime Intellect.
|
| 33 |
{%- endif -%}
|
|
|
|
| 34 |
{%- macro visible_text(content) -%}
|
| 35 |
{%- if content is string -%}
|
| 36 |
{{- content }}
|
|
|
|
| 46 |
{{- content }}
|
| 47 |
{%- endif -%}
|
| 48 |
{%- endmacro -%}
|
|
|
|
| 49 |
{%- set ns = namespace(last_user_index=-1) %}
|
| 50 |
+
{%- for message in messages %}
|
| 51 |
+
{%- if message.role == 'user' %}
|
| 52 |
{% set ns.last_user_index = loop.index0 -%}
|
| 53 |
{%- endif %}
|
| 54 |
{%- endfor %}
|
| 55 |
+
{% for message in messages %}
|
| 56 |
+
{%- if message.role == 'user' -%}<|user|>
|
| 57 |
+
{{ visible_text(message.content) }}
|
| 58 |
+
{%- elif message.role == 'assistant' -%}
|
|
|
|
|
|
|
|
|
|
| 59 |
<|assistant|>
|
| 60 |
+
{%- if message.reasoning_content is defined -%}
|
| 61 |
+
{%- if message.reasoning_content -%}
|
| 62 |
+
{{ '\n<think>' + message.reasoning_content.strip() + '</think>' }}
|
| 63 |
+
{%- else -%}
|
| 64 |
+
{{ '\n<think></think>' }}
|
| 65 |
+
{%- endif -%}
|
| 66 |
+
{%- if message.content.strip() -%}
|
| 67 |
+
{{ '\n' + message.content.strip() }}
|
| 68 |
+
{%- endif -%}
|
| 69 |
{%- else %}
|
| 70 |
+
{{ '\n' + message.content.strip() }}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
{%- endif -%}
|
| 72 |
+
{% if message.tool_calls %}
|
| 73 |
+
{% for tc in message.tool_calls %}
|
|
|
|
| 74 |
{%- if tc.function %}
|
| 75 |
{%- set tc = tc.function %}
|
| 76 |
{%- endif %}
|
|
|
|
| 82 |
{% endfor %}
|
| 83 |
</tool_call>{% endfor %}
|
| 84 |
{% endif %}
|
| 85 |
+
{%- elif message.role == 'tool' -%}
|
| 86 |
+
{%- if message.content is string -%}
|
| 87 |
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
|
| 88 |
{{- '<|observation|>' }}
|
| 89 |
{%- endif %}
|
| 90 |
{{- '\n<tool_response>\n' }}
|
| 91 |
+
{{- message.content }}
|
| 92 |
{{- '\n</tool_response>' }}
|
| 93 |
{%- else -%}
|
| 94 |
<|observation|>{% for tr in m.content %}
|
|
|
|
| 97 |
</tool_response>{% endfor -%}
|
| 98 |
{% endif -%}
|
| 99 |
|
| 100 |
+
{%- elif message.role == 'system' -%}
|
| 101 |
<|system|>
|
| 102 |
+
{{ visible_text(message.content) }}
|
| 103 |
{%- endif -%}
|
| 104 |
|
| 105 |
{%- endfor -%}
|