helixdouble commited on
Commit
ab7e7cc
·
verified ·
1 Parent(s): 61a9fc9

SFT run 3: heretic-v2 base (0/100 refusals), QLoRA rank 32, 2 epochs, 529 conversations

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
chat_template.jinja ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {# Define the macros for XML conversion #}
2
+ {%- macro render_item_list(item_list, tag_name='required') -%}
3
+ {%- if item_list is defined and item_list is iterable and item_list | length > 0 -%}
4
+ <{{ tag_name }}>[{{- item_list | join(", ") -}}]</{{ tag_name }}>
5
+ {%- endif -%}
6
+ {%- endmacro -%}
7
+
8
+ {%- macro render_extra_keys(json_dict, handled_keys) -%}
9
+ {%- if json_dict is mapping -%}
10
+ {%- for json_key in json_dict if json_key not in handled_keys -%}
11
+ <{{ json_key }}>{{ json_dict[json_key] }}</{{ json_key }}>
12
+ {%- endfor -%}
13
+ {%- endif -%}
14
+ {%- endmacro -%}
15
+
16
+
17
+ {%- set image_count = namespace(value=0) %}
18
+ {%- set video_count = namespace(value=0) %}
19
+ {%- set add_vision_id = add_vision_id if add_vision_id is defined else true %}
20
+
21
+ {# Set Instruct mode here #}
22
+
23
+ {%- macro render_content(content, do_vision_count, is_system_content=false) %}
24
+ {%- if content is string %}
25
+ {{- content }}
26
+ {%- elif content is iterable and content is not mapping %}
27
+ {%- for item in content %}
28
+ {%- if 'image' in item or 'image_url' in item or (item is mapping and item.get('type') == 'image') %}
29
+ {%- if is_system_content %}
30
+ {{- raise_exception('System message cannot contain images.') }}
31
+ {%- endif %}
32
+ {%- if do_vision_count %}
33
+ {%- set image_count.value = image_count.value + 1 %}
34
+ {%- endif %}
35
+ {%- if add_vision_id %}
36
+ {{- 'Picture ' ~ image_count.value ~ ': ' }}
37
+ {%- endif %}
38
+ {{- '<|vision_start|><|image_pad|><|vision_end|>' }}
39
+ {%- elif 'video' in item or (item is mapping and item.get('type') == 'video') %}
40
+ {%- if is_system_content %}
41
+ {{- raise_exception('System message cannot contain videos.') }}
42
+ {%- endif %}
43
+ {%- if do_vision_count %}
44
+ {%- set video_count.value = video_count.value + 1 %}
45
+ {%- endif %}
46
+ {%- if add_vision_id %}
47
+ {{- 'Video ' ~ video_count.value ~ ': ' }}
48
+ {%- endif %}
49
+ {{- '<|vision_start|><|video_pad|><|vision_end|>' }}
50
+ {%- elif item is mapping and 'text' in item %}
51
+ {{- item.text }}
52
+ {%- else %}
53
+ {{- raise_exception('Unexpected item type in content.') }}
54
+ {%- endif %}
55
+ {%- endfor %}
56
+ {%- elif content is none or content is undefined %}
57
+ {{- '' }}
58
+ {%- else %}
59
+ {{- raise_exception('Unexpected content type.') }}
60
+ {%- endif %}
61
+ {%- endmacro %}
62
+
63
+ {%- if not messages %}
64
+ {{- raise_exception('No messages provided.') }}
65
+ {%- endif %}
66
+
67
+ {# Flag to prevent double-rendering system prompt #}
68
+ {%- set ns = namespace(system_rendered=false) %}
69
+
70
+ {%- if tools and tools is iterable and tools is not mapping %}
71
+
72
+ {{- '<|im_start|>system\n# Tools\n\nYou have access to the following functions:\n\n<tools>' -}}
73
+ {%- for tool in tools -%}
74
+ {%- set function = tool.function -%}
75
+ {{- "\n<tool>\n<name>" + function.name + "</name>\n<description>" + function.description + "</description>" -}}
76
+ {%- if function.parameters and function.parameters.properties -%}
77
+ {%- for param_name, param_details in function.parameters.properties.items() -%}
78
+ {{- "\n<parameter>\n<name>" + param_name + "</name>\n<type>" + param_details.type + "</type>\n<description>" + (param_details.description | default('')) + "</description>" -}}
79
+ {{- render_item_list(function.parameters.required) -}}
80
+ {{- render_extra_keys(param_details, ['type', 'description']) -}}
81
+ {{- "\n</parameter>" -}}
82
+ {%- endfor -%}
83
+ {%- endif -%}
84
+ {{- "\n</tool>" -}}
85
+ {%- endfor -%}
86
+
87
+ {{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
88
+
89
+ {%- if messages[0].role == 'system' %}
90
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
91
+ {%- if content %}
92
+ {{- '\n\n' + content }}
93
+ {%- endif %}
94
+ {%- set ns.system_rendered = true %}
95
+ {%- endif %}
96
+ {{- '<|im_end|>\n' }}
97
+ {%- else %}
98
+ {%- if messages[0].role == 'system' %}
99
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
100
+ {{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}
101
+ {%- set ns.system_rendered = true %}
102
+ {%- endif %}
103
+ {%- endif %}
104
+
105
+ {# Main Message Loop #}
106
+ {%- for message in messages %}
107
+ {%- if message.role == "system" and ns.system_rendered and loop.first %}
108
+ {%- continue %}
109
+ {%- endif %}
110
+
111
+ {%- set content = render_content(message.content, true)|trim %}
112
+
113
+ {%- if message.role == "system" %}
114
+ {{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}
115
+ {%- elif message.role == "user" %}
116
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>\n' }}
117
+ {%- elif message.role == "assistant" %}
118
+ {%- set reasoning_content = '' %}
119
+ {%- if message.reasoning_content is defined and message.reasoning_content is string %}
120
+ {%- set reasoning_content = message.reasoning_content | trim %}
121
+ {%- elif '<think>' in content and '</think>' in content %}
122
+ {%- set reasoning_content = content.split('</think>')[0].split('<think>')[-1] | trim %}
123
+ {%- set content = content.split('</think>')[-1] | trim %}
124
+ {%- endif %}
125
+
126
+ {{- '<|im_start|>' + message.role + '\n' }}
127
+
128
+ {%- if reasoning_content %}
129
+ {{- '<think>\n' + reasoning_content + '\n</think>\n\n' }}
130
+ {%- endif %}
131
+
132
+ {{- content }}
133
+
134
+ {# Tool call formatting #}
135
+ {%- if message.tool_calls %}
136
+ {%- for tool_call in message.tool_calls %}
137
+ {%- set tc = tool_call.function if tool_call.function is defined else tool_call %}
138
+ {%- if loop.first and content %}{{- '\n\n' }}{%- elif not loop.first %}{{- '\n' }}{%- endif %}
139
+ {{- '<tool_call>\n<function=' + tc.name + '>\n' }}
140
+ {%- for args_name, args_value in tc.arguments|items %}
141
+ {{- '<parameter=' + args_name + '>\n' }}
142
+ {{- (args_value | tojson | safe if args_value is mapping or args_value is sequence else args_value | string) + '\n</parameter>\n' }}
143
+ {%- endfor %}
144
+ {{- '</function>\n</tool_call>' }}
145
+ {%- endfor %}
146
+ {%- endif %}
147
+ {{- '<|im_end|>\n' }}
148
+ {%- elif message.role == "tool" %}
149
+ {%- if loop.previtem and loop.previtem.role != "tool" %}{{- '<|im_start|>user' }}{%- endif %}
150
+ {{- '\n<tool_response>\n' + content + '\n</tool_response>' }}
151
+ {%- if loop.last or (loop.nextitem and loop.nextitem.role != "tool") %}{{- '<|im_end|>\n' }}{%- endif %}
152
+ {%- endif %}
153
+ {%- endfor %}
154
+
155
+ {# Final Generation Prompt #}
156
+ {%- if add_generation_prompt %}
157
+ {{- '<|im_start|>assistant\n' }}
158
+ {%- if enable_thinking is defined and enable_thinking is false %}
159
+ {{- '<think>\n\n</think>\n\n' }}
160
+ {%- else %}
161
+ {{- '<think>\n' }}
162
+ {%- endif %}
163
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen3_5ForConditionalGeneration"
4
+ ],
5
+ "bos_token_id": null,
6
+ "torch_dtype": "bfloat16",
7
+ "eos_token_id": 248046,
8
+ "image_token_id": 248056,
9
+ "model_name": "llmfan46/Qwen3.5-27B-Claude-4.6-Opus-Reasoning-Distilled-heretic-v2",
10
+ "model_type": "qwen3_5",
11
+ "pad_token_id": 248044,
12
+ "text_config": {
13
+ "attention_bias": false,
14
+ "attention_dropout": 0.0,
15
+ "attn_output_gate": true,
16
+ "bos_token_id": null,
17
+ "torch_dtype": "bfloat16",
18
+ "eos_token_id": 248044,
19
+ "full_attention_interval": 4,
20
+ "head_dim": 256,
21
+ "hidden_act": "silu",
22
+ "hidden_size": 5120,
23
+ "initializer_range": 0.02,
24
+ "intermediate_size": 17408,
25
+ "layer_types": [
26
+ "linear_attention",
27
+ "linear_attention",
28
+ "linear_attention",
29
+ "full_attention",
30
+ "linear_attention",
31
+ "linear_attention",
32
+ "linear_attention",
33
+ "full_attention",
34
+ "linear_attention",
35
+ "linear_attention",
36
+ "linear_attention",
37
+ "full_attention",
38
+ "linear_attention",
39
+ "linear_attention",
40
+ "linear_attention",
41
+ "full_attention",
42
+ "linear_attention",
43
+ "linear_attention",
44
+ "linear_attention",
45
+ "full_attention",
46
+ "linear_attention",
47
+ "linear_attention",
48
+ "linear_attention",
49
+ "full_attention",
50
+ "linear_attention",
51
+ "linear_attention",
52
+ "linear_attention",
53
+ "full_attention",
54
+ "linear_attention",
55
+ "linear_attention",
56
+ "linear_attention",
57
+ "full_attention",
58
+ "linear_attention",
59
+ "linear_attention",
60
+ "linear_attention",
61
+ "full_attention",
62
+ "linear_attention",
63
+ "linear_attention",
64
+ "linear_attention",
65
+ "full_attention",
66
+ "linear_attention",
67
+ "linear_attention",
68
+ "linear_attention",
69
+ "full_attention",
70
+ "linear_attention",
71
+ "linear_attention",
72
+ "linear_attention",
73
+ "full_attention",
74
+ "linear_attention",
75
+ "linear_attention",
76
+ "linear_attention",
77
+ "full_attention",
78
+ "linear_attention",
79
+ "linear_attention",
80
+ "linear_attention",
81
+ "full_attention",
82
+ "linear_attention",
83
+ "linear_attention",
84
+ "linear_attention",
85
+ "full_attention",
86
+ "linear_attention",
87
+ "linear_attention",
88
+ "linear_attention",
89
+ "full_attention"
90
+ ],
91
+ "linear_conv_kernel_dim": 4,
92
+ "linear_key_head_dim": 128,
93
+ "linear_num_key_heads": 16,
94
+ "linear_num_value_heads": 48,
95
+ "linear_value_head_dim": 128,
96
+ "mamba_ssm_dtype": "float32",
97
+ "max_position_embeddings": 262144,
98
+ "mlp_only_layers": [],
99
+ "model_type": "qwen3_5_text",
100
+ "mtp_num_hidden_layers": 1,
101
+ "mtp_use_dedicated_embeddings": false,
102
+ "num_attention_heads": 24,
103
+ "num_hidden_layers": 64,
104
+ "num_key_value_heads": 4,
105
+ "pad_token_id": null,
106
+ "partial_rotary_factor": 0.25,
107
+ "rms_norm_eps": 1e-06,
108
+ "rope_parameters": {
109
+ "mrope_interleaved": true,
110
+ "mrope_section": [
111
+ 11,
112
+ 11,
113
+ 10
114
+ ],
115
+ "partial_rotary_factor": 0.25,
116
+ "rope_theta": 10000000,
117
+ "rope_type": "default"
118
+ },
119
+ "tie_word_embeddings": false,
120
+ "use_cache": true,
121
+ "vocab_size": 248320
122
+ },
123
+ "tie_word_embeddings": false,
124
+ "unsloth_version": "2026.3.4",
125
+ "video_token_id": 248057,
126
+ "vision_config": {
127
+ "deepstack_visual_indexes": [],
128
+ "depth": 27,
129
+ "torch_dtype": "bfloat16",
130
+ "hidden_act": "gelu_pytorch_tanh",
131
+ "hidden_size": 1152,
132
+ "in_channels": 3,
133
+ "initializer_range": 0.02,
134
+ "intermediate_size": 4304,
135
+ "model_type": "qwen3_5",
136
+ "num_heads": 16,
137
+ "num_position_embeddings": 2304,
138
+ "out_hidden_size": 5120,
139
+ "patch_size": 16,
140
+ "spatial_merge_size": 2,
141
+ "temporal_patch_size": 2
142
+ },
143
+ "vision_end_token_id": 248054,
144
+ "vision_start_token_id": 248053
145
+ }
model-00001-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:59786c5fab8b7f7d91d780d74a04dc3c5e23355cf4fa89a67d1a7115d74a240f
3
+ size 49825162976
model-00002-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ec677082d59992654a1b0bf13b2294f7bec6d2ecb315428a83f7ba97ec456b6b
3
+ size 4888445168
model.safetensors.index.json ADDED
The diff for this file is too large to render. See raw diff
 
processor_config.json ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "image_processor": {
3
+ "data_format": "channels_first",
4
+ "do_convert_rgb": true,
5
+ "do_normalize": true,
6
+ "do_rescale": true,
7
+ "do_resize": true,
8
+ "image_mean": [
9
+ 0.5,
10
+ 0.5,
11
+ 0.5
12
+ ],
13
+ "image_processor_type": "Qwen2VLImageProcessorFast",
14
+ "image_std": [
15
+ 0.5,
16
+ 0.5,
17
+ 0.5
18
+ ],
19
+ "merge_size": 2,
20
+ "patch_size": 16,
21
+ "resample": 3,
22
+ "rescale_factor": 0.00392156862745098,
23
+ "size": {
24
+ "longest_edge": 16777216,
25
+ "shortest_edge": 65536
26
+ },
27
+ "temporal_patch_size": 2
28
+ },
29
+ "processor_class": "Qwen3VLProcessor",
30
+ "video_processor": {
31
+ "data_format": "channels_first",
32
+ "default_to_square": true,
33
+ "do_convert_rgb": true,
34
+ "do_normalize": true,
35
+ "do_rescale": true,
36
+ "do_resize": true,
37
+ "do_sample_frames": true,
38
+ "fps": 2,
39
+ "image_mean": [
40
+ 0.5,
41
+ 0.5,
42
+ 0.5
43
+ ],
44
+ "image_std": [
45
+ 0.5,
46
+ 0.5,
47
+ 0.5
48
+ ],
49
+ "max_frames": 768,
50
+ "merge_size": 2,
51
+ "min_frames": 4,
52
+ "patch_size": 16,
53
+ "resample": 3,
54
+ "rescale_factor": 0.00392156862745098,
55
+ "return_metadata": false,
56
+ "size": {
57
+ "longest_edge": 25165824,
58
+ "shortest_edge": 4096
59
+ },
60
+ "temporal_patch_size": 2,
61
+ "video_processor_type": "Qwen3VLVideoProcessor"
62
+ }
63
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:639e352c0f904c1875d448ebed6f6faac005fd3eb58393b7f1fb3ff044e5ca03
3
+ size 19989510
tokenizer_config.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "audio_bos_token": "<|audio_start|>",
4
+ "audio_eos_token": "<|audio_end|>",
5
+ "audio_token": "<|audio_pad|>",
6
+ "backend": "tokenizers",
7
+ "bos_token": null,
8
+ "clean_up_tokenization_spaces": false,
9
+ "eos_token": "<|im_end|>",
10
+ "errors": "replace",
11
+ "image_token": "<|image_pad|>",
12
+ "is_local": false,
13
+ "max_length": null,
14
+ "model_max_length": 262144,
15
+ "model_specific_special_tokens": {
16
+ "audio_bos_token": "<|audio_start|>",
17
+ "audio_eos_token": "<|audio_end|>",
18
+ "audio_token": "<|audio_pad|>",
19
+ "image_token": "<|image_pad|>",
20
+ "video_token": "<|video_pad|>",
21
+ "vision_bos_token": "<|vision_start|>",
22
+ "vision_eos_token": "<|vision_end|>"
23
+ },
24
+ "pad_to_multiple_of": null,
25
+ "pad_token": "<|endoftext|>",
26
+ "pad_token_type_id": 0,
27
+ "padding_side": "left",
28
+ "pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+",
29
+ "processor_class": "Qwen3VLProcessor",
30
+ "split_special_tokens": false,
31
+ "tokenizer_class": "Qwen2Tokenizer",
32
+ "unk_token": null,
33
+ "video_token": "<|video_pad|>",
34
+ "vision_bos_token": "<|vision_start|>",
35
+ "vision_eos_token": "<|vision_end|>",
36
+ "chat_template": "{# Define the macros for XML conversion #}\n{%- macro render_item_list(item_list, tag_name='required') -%}\n {%- if item_list is defined and item_list is iterable and item_list | length > 0 -%}\n <{{ tag_name }}>[{{- item_list | join(\", \") -}}]</{{ tag_name }}>\n {%- endif -%}\n{%- endmacro -%}\n\n{%- macro render_extra_keys(json_dict, handled_keys) -%}\n {%- if json_dict is mapping -%}\n {%- for json_key in json_dict if json_key not in handled_keys -%}\n <{{ json_key }}>{{ json_dict[json_key] }}</{{ json_key }}>\n {%- endfor -%}\n {%- endif -%}\n{%- endmacro -%}\n\n\n{%- set image_count = namespace(value=0) %}\n{%- set video_count = namespace(value=0) %}\n{%- set add_vision_id = add_vision_id if add_vision_id is defined else true %}\n\n{# Set Instruct mode here #}\n\n{%- macro render_content(content, do_vision_count, is_system_content=false) %}\n {%- if content is string %}\n {{- content }}\n {%- elif content is iterable and content is not mapping %}\n {%- for item in content %}\n {%- if 'image' in item or 'image_url' in item or (item is mapping and item.get('type') == 'image') %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain images.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set image_count.value = image_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Picture ' ~ image_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|image_pad|><|vision_end|>' }}\n {%- elif 'video' in item or (item is mapping and item.get('type') == 'video') %}\n {%- if is_system_content %}\n {{- raise_exception('System message cannot contain videos.') }}\n {%- endif %}\n {%- if do_vision_count %}\n {%- set video_count.value = video_count.value + 1 %}\n {%- endif %}\n {%- if add_vision_id %}\n {{- 'Video ' ~ video_count.value ~ ': ' }}\n {%- endif %}\n {{- '<|vision_start|><|video_pad|><|vision_end|>' }}\n {%- elif item is mapping and 'text' in item %}\n {{- item.text }}\n {%- else %}\n {{- raise_exception('Unexpected item type in content.') }}\n {%- endif %}\n {%- endfor %}\n {%- elif content is none or content is undefined %}\n {{- '' }}\n {%- else %}\n {{- raise_exception('Unexpected content type.') }}\n {%- endif %}\n{%- endmacro %}\n\n{%- if not messages %}\n {{- raise_exception('No messages provided.') }}\n{%- endif %}\n\n{# Flag to prevent double-rendering system prompt #}\n{%- set ns = namespace(system_rendered=false) %}\n\n{%- if tools and tools is iterable and tools is not mapping %}\n\n {{- '<|im_start|>system\\n# Tools\\n\\nYou have access to the following functions:\\n\\n<tools>' -}}\n {%- for tool in tools -%}\n {%- set function = tool.function -%}\n {{- \"\\n<tool>\\n<name>\" + function.name + \"</name>\\n<description>\" + function.description + \"</description>\" -}}\n {%- if function.parameters and function.parameters.properties -%}\n {%- for param_name, param_details in function.parameters.properties.items() -%}\n {{- \"\\n<parameter>\\n<name>\" + param_name + \"</name>\\n<type>\" + param_details.type + \"</type>\\n<description>\" + (param_details.description | default('')) + \"</description>\" -}}\n {{- render_item_list(function.parameters.required) -}}\n {{- render_extra_keys(param_details, ['type', 'description']) -}}\n {{- \"\\n</parameter>\" -}}\n {%- endfor -%}\n {%- endif -%}\n {{- \"\\n</tool>\" -}}\n {%- endfor -%}\n\n {{- '\\n\\nIf you choose to call a function ONLY reply in the following format with NO suffix:\\n\\n<tool_call>\\n<function=example_function_name>\\n<parameter=example_parameter_1>\\nvalue_1\\n</parameter>\\n<parameter=example_parameter_2>\\nThis is the value for the second parameter\\nthat can span\\nmultiple lines\\n</parameter>\\n</function>\\n</tool_call>\\n\\n<IMPORTANT>\\nReminder:\\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\\n- Required parameters MUST be specified\\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\\n</IMPORTANT>' }}\n \n {%- if messages[0].role == 'system' %}\n {%- set content = render_content(messages[0].content, false, true)|trim %}\n {%- if content %}\n {{- '\\n\\n' + content }}\n {%- endif %}\n {%- set ns.system_rendered = true %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n{%- else %}\n {%- if messages[0].role == 'system' %}\n {%- set content = render_content(messages[0].content, false, true)|trim %}\n {{- '<|im_start|>system\\n' + content + '<|im_end|>\\n' }}\n {%- set ns.system_rendered = true %}\n {%- endif %}\n{%- endif %}\n\n{# Main Message Loop #}\n{%- for message in messages %}\n {%- if message.role == \"system\" and ns.system_rendered and loop.first %}\n {%- continue %}\n {%- endif %}\n\n {%- set content = render_content(message.content, true)|trim %}\n \n {%- if message.role == \"system\" %}\n {{- '<|im_start|>system\\n' + content + '<|im_end|>\\n' }}\n {%- elif message.role == \"user\" %}\n {{- '<|im_start|>' + message.role + '\\n' + content + '<|im_end|>\\n' }}\n {%- elif message.role == \"assistant\" %}\n {%- set reasoning_content = '' %}\n {%- if message.reasoning_content is defined and message.reasoning_content is string %}\n {%- set reasoning_content = message.reasoning_content | trim %}\n {%- elif '<think>' in content and '</think>' in content %}\n {%- set reasoning_content = content.split('</think>')[0].split('<think>')[-1] | trim %}\n {%- set content = content.split('</think>')[-1] | trim %}\n {%- endif %}\n\n {{- '<|im_start|>' + message.role + '\\n' }}\n \n {%- if reasoning_content %}\n {{- '<think>\\n' + reasoning_content + '\\n</think>\\n\\n' }}\n {%- endif %}\n \n {{- content }}\n\n {# Tool call formatting #}\n {%- if message.tool_calls %}\n {%- for tool_call in message.tool_calls %}\n {%- set tc = tool_call.function if tool_call.function is defined else tool_call %}\n {%- if loop.first and content %}{{- '\\n\\n' }}{%- elif not loop.first %}{{- '\\n' }}{%- endif %}\n {{- '<tool_call>\\n<function=' + tc.name + '>\\n' }}\n {%- for args_name, args_value in tc.arguments|items %}\n {{- '<parameter=' + args_name + '>\\n' }}\n {{- (args_value | tojson | safe if args_value is mapping or args_value is sequence else args_value | string) + '\\n</parameter>\\n' }}\n {%- endfor %}\n {{- '</function>\\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if loop.previtem and loop.previtem.role != \"tool\" %}{{- '<|im_start|>user' }}{%- endif %}\n {{- '\\n<tool_response>\\n' + content + '\\n</tool_response>' }}\n {%- if loop.last or (loop.nextitem and loop.nextitem.role != \"tool\") %}{{- '<|im_end|>\\n' }}{%- endif %}\n {%- endif %}\n{%- endfor %}\n\n{# Final Generation Prompt #}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n {%- if enable_thinking is defined and enable_thinking is false %}\n {{- '<think>\\n\\n</think>\\n\\n' }}\n {%- else %}\n {{- '<think>\\n' }}\n {%- endif %}\n{%- endif %}"
37
+ }