danielhanchen commited on
Commit
bbfc14e
·
verified ·
1 Parent(s): f6a5914

Update chat_template.jinja

Browse files
Files changed (1) hide show
  1. chat_template.jinja +11 -9
chat_template.jinja CHANGED
@@ -43,8 +43,7 @@ For each function call, output the function name and arguments within the follow
43
  {%- endfor %}
44
  {% for m in messages %}
45
  {%- if m.role == 'user' -%}<|user|>
46
- {%- set content = visible_text(m.content)|string %}
47
- {{ content }}
48
  {{- '/nothink' if (enable_thinking is defined and not enable_thinking and not content.endswith("/nothink")) else '' -}}
49
  {%- elif m.role == 'assistant' -%}
50
  <|assistant|>
@@ -53,13 +52,16 @@ For each function call, output the function name and arguments within the follow
53
  {%- if m.reasoning_content is defined and m.reasoning_content is string %}
54
  {%- set reasoning_content = m.reasoning_content %}
55
  {%- else %}
56
- {%- if content is string and '</think>' in content %}
57
- {%- set reasoning_content = content.split('</think>') -%}
58
- {%- set content = reasoning_content[-1].lstrip('\n') %}
59
- {%- set reasoning_content = reasoning_content[0] %}
60
- {%- set reasoning_content = reasoning_content.split('<think>')[-1] if '<think>' in reasoning_content else '' -%}
61
- {%- set reasoning_content = reasoning_content.lstrip('\n').rstrip('\n') -%}
62
- {%- endif %}
 
 
 
63
  {%- endif %}
64
  {%- if loop.index0 > ns.last_user_index and reasoning_content -%}
65
  {{ '\n<think>' + reasoning_content.strip() + '</think>'}}
 
43
  {%- endfor %}
44
  {% for m in messages %}
45
  {%- if m.role == 'user' -%}<|user|>
46
+ {%- set content = visible_text(m.content)|string %}{{ content }}
 
47
  {{- '/nothink' if (enable_thinking is defined and not enable_thinking and not content.endswith("/nothink")) else '' -}}
48
  {%- elif m.role == 'assistant' -%}
49
  <|assistant|>
 
52
  {%- if m.reasoning_content is defined and m.reasoning_content is string %}
53
  {%- set reasoning_content = m.reasoning_content %}
54
  {%- else %}
55
+ {# Unsloth template fixes - must change to for loop since llama.cpp will error out if not #}
56
+ {%- set parts = content.split('</think>') %}
57
+ {% for part in parts %}
58
+ {%- if loop.index0 == 0 -%}
59
+ {%- set reasoning_content = part.split("<think>")[-1] %}
60
+ {%- set reasoning_content = reasoning_content.lstrip('\n').rstrip('\n') -%}
61
+ {%- else -%}
62
+ {%- set content = part.lstrip('\n') %}
63
+ {%- endif %}
64
+ {%- endfor %}
65
  {%- endif %}
66
  {%- if loop.index0 > ns.last_user_index and reasoning_content -%}
67
  {{ '\n<think>' + reasoning_content.strip() + '</think>'}}