Iceberg-Yang commited on
Commit
412f8b6
·
verified ·
1 Parent(s): 452438e

Upload chat_template.jinja with huggingface_hub

Browse files
Files changed (1) hide show
  1. chat_template.jinja +24 -33
chat_template.jinja CHANGED
@@ -27,11 +27,6 @@
27
  {{- 'Video ' ~ video_count.value ~ ': ' }}
28
  {%- endif %}
29
  {{- '<|vision_start|><|video_pad|><|vision_end|>' }}
30
- {%- elif 'audio' in item or item.type == 'audio' %}
31
- {%- if is_system_content %}
32
- {{- raise_exception('System message cannot contain audio.') }}
33
- {%- endif %}
34
- {{- '<|audio_start|><|audio_pad|><|audio_end|>' }}
35
  {%- elif 'text' in item %}
36
  {{- item.text }}
37
  {%- else %}
@@ -44,29 +39,26 @@
44
  {{- raise_exception('Unexpected content type.') }}
45
  {%- endif %}
46
  {%- endmacro %}
47
- {#- Dynamic reasoning_effort (low/high/xhigh): low & xhigh inject a system directive line; high or unset = no injection (== high). #}
48
- {%- if reasoning_effort is defined and reasoning_effort is not none %}
49
- {%- if reasoning_effort not in ['low', 'high', 'xhigh'] %}
50
- {{- raise_exception('Unknown reasoning_effort: ' + reasoning_effort|string + '. Expected one of: low, high, xhigh.') }}
51
- {%- endif %}
52
- {%- endif %}
53
- {%- set add_reasoning = reasoning_effort is defined and reasoning_effort is not none and reasoning_effort in ['low', 'xhigh'] %}
54
- {%- if add_reasoning %}
55
- {%- if reasoning_effort == 'low' %}
56
- {%- set reasoning_line = 'Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.' %}
57
- {%- elif reasoning_effort == 'xhigh' %}
58
- {%- set reasoning_line = '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.' %}
59
- {%- endif %}
60
- {%- set reasoning_prefix = reasoning_line + '\n\n' %}
61
- {%- else %}
62
- {%- set reasoning_prefix = '' %}
63
- {%- endif %}
64
  {%- if not messages %}
65
  {{- raise_exception('No messages provided.') }}
66
  {%- endif %}
 
 
 
 
 
 
 
 
 
 
 
 
67
  {%- if tools and tools is iterable and tools is not mapping %}
68
  {{- '<|im_start|>system\n' }}
69
- {{- reasoning_prefix }}
 
 
70
  {{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
71
  {%- for tool in tools %}
72
  {{- "\n" }}
@@ -84,9 +76,13 @@
84
  {%- else %}
85
  {%- if messages[0].role == 'system' %}
86
  {%- set content = render_content(messages[0].content, false, true)|trim %}
87
- {{- '<|im_start|>system\n' + reasoning_prefix + content + '<|im_end|>\n' }}
88
- {%- elif add_reasoning %}
89
- {{- '<|im_start|>system\n' + reasoning_line + '<|im_end|>\n' }}
 
 
 
 
90
  {%- endif %}
91
  {%- endif %}
92
  {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
@@ -115,14 +111,9 @@
115
  {%- set reasoning_content = '' %}
116
  {%- if message.reasoning_content is string %}
117
  {%- set reasoning_content = message.reasoning_content %}
118
- {%- else %}
119
- {%- if '</think>' in content %}
120
- {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
121
- {%- set content = content.split('</think>')[-1].lstrip('\n') %}
122
- {%- endif %}
123
  {%- endif %}
124
  {%- set reasoning_content = reasoning_content|trim %}
125
- {%- if (preserve_thinking is defined and preserve_thinking is true) or (loop.index0 > ns.last_query_index) %}
126
  {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
127
  {%- else %}
128
  {{- '<|im_start|>' + message.role + '\n' + content }}
@@ -141,7 +132,7 @@
141
  {%- else %}
142
  {{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
143
  {%- endif %}
144
- {%- if tool_call.arguments is defined %}
145
  {%- for args_name, args_value in tool_call.arguments|items %}
146
  {{- '<parameter=' + args_name + '>\n' }}
147
  {%- set args_value = args_value | string if args_value is string else args_value | tojson | safe %}
 
27
  {{- 'Video ' ~ video_count.value ~ ': ' }}
28
  {%- endif %}
29
  {{- '<|vision_start|><|video_pad|><|vision_end|>' }}
 
 
 
 
 
30
  {%- elif 'text' in item %}
31
  {{- item.text }}
32
  {%- else %}
 
39
  {{- raise_exception('Unexpected content type.') }}
40
  {%- endif %}
41
  {%- endmacro %}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  {%- if not messages %}
43
  {{- raise_exception('No messages provided.') }}
44
  {%- endif %}
45
+ {%- set reasoning_instructions = '' %}
46
+ {%- if enable_thinking is undefined or enable_thinking is true %}
47
+ {%- set resolved_reasoning_effort = reasoning_effort|default('xhigh') %}
48
+ {%- if resolved_reasoning_effort not in ('xhigh', 'medium', 'low') %}
49
+ {{- raise_exception('Unexpected reasoning effort ' ~ reasoning_effort ~ '. Supported types are xhigh (default), medium, and low.') }}
50
+ {%- endif %}
51
+ {%- if resolved_reasoning_effort == 'xhigh' %}
52
+ {%- 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.' %}
53
+ {%- elif resolved_reasoning_effort == 'low' %}
54
+ {%- set reasoning_instructions = 'Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.' %}
55
+ {%- endif %}
56
+ {%- endif %}
57
  {%- if tools and tools is iterable and tools is not mapping %}
58
  {{- '<|im_start|>system\n' }}
59
+ {%- if reasoning_instructions %}
60
+ {{- reasoning_instructions + '\n\n' }}
61
+ {%- endif %}
62
  {{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
63
  {%- for tool in tools %}
64
  {{- "\n" }}
 
76
  {%- else %}
77
  {%- if messages[0].role == 'system' %}
78
  {%- set content = render_content(messages[0].content, false, true)|trim %}
79
+ {%- if content %}
80
+ {{- '<|im_start|>system\n' + (reasoning_instructions + '\n\n' if reasoning_instructions else '') + content + '<|im_end|>\n' }}
81
+ {%- elif reasoning_instructions %}
82
+ {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
83
+ {%- endif %}
84
+ {%- elif reasoning_instructions %}
85
+ {{- '<|im_start|>system\n' + reasoning_instructions + '<|im_end|>\n' }}
86
  {%- endif %}
87
  {%- endif %}
88
  {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
 
111
  {%- set reasoning_content = '' %}
112
  {%- if message.reasoning_content is string %}
113
  {%- set reasoning_content = message.reasoning_content %}
 
 
 
 
 
114
  {%- endif %}
115
  {%- set reasoning_content = reasoning_content|trim %}
116
+ {%- if preserve_thinking is undefined or preserve_thinking is true or loop.index0 > ns.last_query_index %}
117
  {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
118
  {%- else %}
119
  {{- '<|im_start|>' + message.role + '\n' + content }}
 
132
  {%- else %}
133
  {{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
134
  {%- endif %}
135
+ {%- if tool_call.arguments is defined and tool_call.arguments != '' %}
136
  {%- for args_name, args_value in tool_call.arguments|items %}
137
  {{- '<parameter=' + args_name + '>\n' }}
138
  {%- set args_value = args_value | string if args_value is string else args_value | tojson | safe %}
Free AI Image Generator No sign-up. Instant results. Open Now