danielhanchen commited on
Commit
0b7c63a
·
verified ·
1 Parent(s): 81620e1

Update chat_template.jinja

Browse files
Files changed (1) hide show
  1. chat_template.jinja +13 -2
chat_template.jinja CHANGED
@@ -1,3 +1,4 @@
 
1
  {%- set image_count = namespace(value=0) %}
2
  {%- set video_count = namespace(value=0) %}
3
  {%- macro render_content(content, do_vision_count) %}
@@ -60,8 +61,17 @@
60
  {%- set reasoning_content = message.reasoning_content %}
61
  {%- else %}
62
  {%- if '</think>' in content %}
63
- {%- set reasoning_content = ((content.split('</think>')|first).rstrip('\n').split('<think>')|last).lstrip('\n') %}
64
- {%- set content = (content.split('</think>')|last).lstrip('\n') %}
 
 
 
 
 
 
 
 
 
65
  {%- endif %}
66
  {%- endif %}
67
  {%- if loop.index0 > ns.last_query_index %}
@@ -108,3 +118,4 @@
108
  {%- if add_generation_prompt %}
109
  {{- '<|im_start|>assistant\n<think>\n' }}
110
  {%- endif %}
 
 
1
+ {# Unsloth template fixes #}
2
  {%- set image_count = namespace(value=0) %}
3
  {%- set video_count = namespace(value=0) %}
4
  {%- macro render_content(content, do_vision_count) %}
 
61
  {%- set reasoning_content = message.reasoning_content %}
62
  {%- else %}
63
  {%- if '</think>' in content %}
64
+ {# Unsloth template fixes - must change to for loop since llama.cpp will error out if not #}
65
+ {%- set parts = content.split('</think>') %}
66
+ {%- for part in parts %}
67
+ {%- if loop.index0 == 0 -%}
68
+ {%- set reasoning_content = part.rstrip('\n') %}
69
+ {%- set reasoning_content = (reasoning_content.split('<think>')|last) %}
70
+ {%- set reasoning_content = reasoning_content.lstrip('\n') -%}
71
+ {%- else -%}
72
+ {%- set content = part.lstrip('\n') %}
73
+ {%- endif %}
74
+ {%- endfor %}
75
  {%- endif %}
76
  {%- endif %}
77
  {%- if loop.index0 > ns.last_query_index %}
 
118
  {%- if add_generation_prompt %}
119
  {{- '<|im_start|>assistant\n<think>\n' }}
120
  {%- endif %}
121
+ {# Copyright 2025-present Unsloth. Apache 2.0 License. #}