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os>",
|
| 11 |
+
"eot_token": "<turn|>",
|
| 12 |
+
"escape_token": "<|\"|>",
|
| 13 |
+
"etc_token": "<tool_call|>",
|
| 14 |
+
"etd_token": "<tool|>",
|
| 15 |
+
"etr_token": "<tool_response|>",
|
| 16 |
+
"extra_special_tokens": [
|
| 17 |
+
"<|video|>"
|
| 18 |
+
],
|
| 19 |
+
"image_token": "<|image|>",
|
| 20 |
+
"is_local": false,
|
| 21 |
+
"local_files_only": false,
|
| 22 |
+
"mask_token": "<mask>",
|
| 23 |
+
"model_max_length": 131072,
|
| 24 |
+
"model_specific_special_tokens": {
|
| 25 |
+
"audio_token": "<|audio|>",
|
| 26 |
+
"boa_token": "<|audio>",
|
| 27 |
+
"boi_token": "<|image>",
|
| 28 |
+
"eoa_token": "<audio|>",
|
| 29 |
+
"eoc_token": "<channel|>",
|
| 30 |
+
"eoi_token": "<image|>",
|
| 31 |
+
"eot_token": "<turn|>",
|
| 32 |
+
"escape_token": "<|\"|>",
|
| 33 |
+
"etc_token": "<tool_call|>",
|
| 34 |
+
"etd_token": "<tool|>",
|
| 35 |
+
"etr_token": "<tool_response|>",
|
| 36 |
+
"image_token": "<|image|>",
|
| 37 |
+
"soc_token": "<|channel>",
|
| 38 |
+
"sot_token": "<|turn>",
|
| 39 |
+
"stc_token": "<|tool_call>",
|
| 40 |
+
"std_token": "<|tool>",
|
| 41 |
+
"str_token": "<|tool_response>",
|
| 42 |
+
"think_token": "<|think|>"
|
| 43 |
+
},
|
| 44 |
+
"pad_token": "<pad>",
|
| 45 |
+
"padding_side": "right",
|
| 46 |
+
"processor_class": "Gemma4Processor",
|
| 47 |
+
"response_schema": {
|
| 48 |
+
"properties": {
|
| 49 |
+
"content": {
|
| 50 |
+
"type": "string"
|
| 51 |
+
},
|
| 52 |
+
"role": {
|
| 53 |
+
"const": "assistant"
|
| 54 |
+
},
|
| 55 |
+
"thinking": {
|
| 56 |
+
"type": "string"
|
| 57 |
+
},
|
| 58 |
+
"tool_calls": {
|
| 59 |
+
"items": {
|
| 60 |
+
"properties": {
|
| 61 |
+
"function": {
|
| 62 |
+
"properties": {
|
| 63 |
+
"arguments": {
|
| 64 |
+
"additionalProperties": {},
|
| 65 |
+
"type": "object",
|
| 66 |
+
"x-parser": "gemma4-tool-call"
|
| 67 |
+
},
|
| 68 |
+
"name": {
|
| 69 |
+
"type": "string"
|
| 70 |
+
}
|
| 71 |
+
},
|
| 72 |
+
"type": "object",
|
| 73 |
+
"x-regex": "call\\:(?P<name>\\w+)(?P<arguments>\\{.*\\})"
|
| 74 |
+
},
|
| 75 |
+
"type": {
|
| 76 |
+
"const": "function"
|
| 77 |
+
}
|
| 78 |
+
},
|
| 79 |
+
"type": "object"
|
| 80 |
+
},
|
| 81 |
+
"type": "array",
|
| 82 |
+
"x-regex-iterator": "<\\|tool_call>(.*?)<tool_call\\|>"
|
| 83 |
+
}
|
| 84 |
+
},
|
| 85 |
+
"type": "object",
|
| 86 |
+
"x-regex": "(\\<\\|channel\\>thought\\n(?P<thinking>.*?)\\<channel\\|\\>)?(?P<tool_calls>\\<\\|tool_call\\>.*\\<tool_call\\|\\>)?(?P<content>(?:(?!\\<turn\\|\\>)(?!\\<\\|tool_response\\>).)+)?(?:\\<turn\\|\\>|\\<\\|tool_response\\>)?"
|
| 87 |
+
},
|
| 88 |
+
"soc_token": "<|channel>",
|
| 89 |
+
"sot_token": "<|turn>",
|
| 90 |
+
"stc_token": "<|tool_call>",
|
| 91 |
+
"std_token": "<|tool>",
|
| 92 |
+
"str_token": "<|tool_response>",
|
| 93 |
+
"think_token": "<|think|>",
|
| 94 |
+
"tokenizer_class": "GemmaTokenizer",
|
| 95 |
+
"unk_token": "<unk>",
|
| 96 |
+
"added_tokens_decoder": {
|
| 97 |
+
"0": {
|
| 98 |
+
"content": "<pad>",
|
| 99 |
+
"single_word": false,
|
| 100 |
+
"lstrip": false,
|
| 101 |
+
"rstrip": false,
|
| 102 |
+
"normalized": false,
|
| 103 |
+
"special": true
|
| 104 |
+
},
|
| 105 |
+
"1": {
|
| 106 |
+
"content": "<eos>",
|
| 107 |
+
"single_word": false,
|
| 108 |
+
"lstrip": false,
|
| 109 |
+
"rstrip": false,
|
| 110 |
+
"normalized": false,
|
| 111 |
+
"special": true
|
| 112 |
+
},
|
| 113 |
+
"2": {
|
| 114 |
+
"content": "<bos>",
|
| 115 |
+
"single_word": false,
|
| 116 |
+
"lstrip": false,
|
| 117 |
+
"rstrip": false,
|
| 118 |
+
"normalized": false,
|
| 119 |
+
"special": true
|
| 120 |
+
},
|
| 121 |
+
"3": {
|
| 122 |
+
"content": "<unk>",
|
| 123 |
+
"single_word": false,
|
| 124 |
+
"lstrip": false,
|
| 125 |
+
"rstrip": false,
|
| 126 |
+
"normalized": false,
|
| 127 |
+
"special": true
|
| 128 |
+
},
|
| 129 |
+
"4": {
|
| 130 |
+
"content": "<mask>",
|
| 131 |
+
"single_word": false,
|
| 132 |
+
"lstrip": false,
|
| 133 |
+
"rstrip": false,
|
| 134 |
+
"normalized": false,
|
| 135 |
+
"special": true
|
| 136 |
+
},
|
| 137 |
+
"46": {
|
| 138 |
+
"content": "<|tool>",
|
| 139 |
+
"single_word": false,
|
| 140 |
+
"lstrip": false,
|
| 141 |
+
"rstrip": false,
|
| 142 |
+
"normalized": false,
|
| 143 |
+
"special": true
|
| 144 |
+
},
|
| 145 |
+
"47": {
|
| 146 |
+
"content": "<tool|>",
|
| 147 |
+
"single_word": false,
|
| 148 |
+
"lstrip": false,
|
| 149 |
+
"rstrip": false,
|
| 150 |
+
"normalized": false,
|
| 151 |
+
"special": true
|
| 152 |
+
},
|
| 153 |
+
"48": {
|
| 154 |
+
"content": "<|tool_call>",
|
| 155 |
+
"single_word": false,
|
| 156 |
+
"lstrip": false,
|
| 157 |
+
"rstrip": false,
|
| 158 |
+
"normalized": false,
|
| 159 |
+
"special": true
|
| 160 |
+
},
|
| 161 |
+
"49": {
|
| 162 |
+
"content": "<tool_call|>",
|
| 163 |
+
"single_word": false,
|
| 164 |
+
"lstrip": false,
|
| 165 |
+
"rstrip": false,
|
| 166 |
+
"normalized": false,
|
| 167 |
+
"special": true
|
| 168 |
+
},
|
| 169 |
+
"50": {
|
| 170 |
+
"content": "<|tool_response>",
|
| 171 |
+
"single_word": false,
|
| 172 |
+
"lstrip": false,
|
| 173 |
+
"rstrip": false,
|
| 174 |
+
"normalized": false,
|
| 175 |
+
"special": true
|
| 176 |
+
},
|
| 177 |
+
"51": {
|
| 178 |
+
"content": "<tool_response|>",
|
| 179 |
+
"single_word": false,
|
| 180 |
+
"lstrip": false,
|
| 181 |
+
"rstrip": false,
|
| 182 |
+
"normalized": false,
|
| 183 |
+
"special": true
|
| 184 |
+
},
|
| 185 |
+
"52": {
|
| 186 |
+
"content": "<|\"|>",
|
| 187 |
+
"single_word": false,
|
| 188 |
+
"lstrip": false,
|
| 189 |
+
"rstrip": false,
|
| 190 |
+
"normalized": false,
|
| 191 |
+
"special": true
|
| 192 |
+
},
|
| 193 |
+
"98": {
|
| 194 |
+
"content": "<|think|>",
|
| 195 |
+
"single_word": false,
|
| 196 |
+
"lstrip": false,
|
| 197 |
+
"rstrip": false,
|
| 198 |
+
"normalized": false,
|
| 199 |
+
"special": true
|
| 200 |
+
},
|
| 201 |
+
"100": {
|
| 202 |
+
"content": "<|channel>",
|
| 203 |
+
"single_word": false,
|
| 204 |
+
"lstrip": false,
|
| 205 |
+
"rstrip": false,
|
| 206 |
+
"normalized": false,
|
| 207 |
+
"special": true
|
| 208 |
+
},
|
| 209 |
+
"101": {
|
| 210 |
+
"content": "<channel|>",
|
| 211 |
+
"single_word": false,
|
| 212 |
+
"lstrip": false,
|
| 213 |
+
"rstrip": false,
|
| 214 |
+
"normalized": false,
|
| 215 |
+
"special": true
|
| 216 |
+
},
|
| 217 |
+
"105": {
|
| 218 |
+
"content": "<|turn>",
|
| 219 |
+
"single_word": false,
|
| 220 |
+
"lstrip": false,
|
| 221 |
+
"rstrip": false,
|
| 222 |
+
"normalized": false,
|
| 223 |
+
"special": true
|
| 224 |
+
},
|
| 225 |
+
"106": {
|
| 226 |
+
"content": "<turn|>",
|
| 227 |
+
"single_word": false,
|
| 228 |
+
"lstrip": false,
|
| 229 |
+
"rstrip": false,
|
| 230 |
+
"normalized": false,
|
| 231 |
+
"special": true
|
| 232 |
+
},
|
| 233 |
+
"255999": {
|
| 234 |
+
"content": "<|image>",
|
| 235 |
+
"single_word": false,
|
| 236 |
+
"lstrip": false,
|
| 237 |
+
"rstrip": false,
|
| 238 |
+
"normalized": false,
|
| 239 |
+
"special": true
|
| 240 |
+
},
|
| 241 |
+
"256000": {
|
| 242 |
+
"content": "<|audio>",
|
| 243 |
+
"single_word": false,
|
| 244 |
+
"lstrip": false,
|
| 245 |
+
"rstrip": false,
|
| 246 |
+
"normalized": false,
|
| 247 |
+
"special": true
|
| 248 |
+
},
|
| 249 |
+
"258880": {
|
| 250 |
+
"content": "<|image|>",
|
| 251 |
+
"single_word": false,
|
| 252 |
+
"lstrip": false,
|
| 253 |
+
"rstrip": false,
|
| 254 |
+
"normalized": false,
|
| 255 |
+
"special": true
|
| 256 |
+
},
|
| 257 |
+
"258881": {
|
| 258 |
+
"content": "<|audio|>",
|
| 259 |
+
"single_word": false,
|
| 260 |
+
"lstrip": false,
|
| 261 |
+
"rstrip": false,
|
| 262 |
+
"normalized": false,
|
| 263 |
+
"special": true
|
| 264 |
+
},
|
| 265 |
+
"258882": {
|
| 266 |
+
"content": "<image|>",
|
| 267 |
+
"single_word": false,
|
| 268 |
+
"lstrip": false,
|
| 269 |
+
"rstrip": false,
|
| 270 |
+
"normalized": false,
|
| 271 |
+
"special": true
|
| 272 |
+
},
|
| 273 |
+
"258883": {
|
| 274 |
+
"content": "<audio|>",
|
| 275 |
+
"single_word": false,
|
| 276 |
+
"lstrip": false,
|
| 277 |
+
"rstrip": false,
|
| 278 |
+
"normalized": false,
|
| 279 |
+
"special": true
|
| 280 |
+
},
|
| 281 |
+
"258884": {
|
| 282 |
+
"content": "<|video|>",
|
| 283 |
+
"single_word": false,
|
| 284 |
+
"lstrip": false,
|
| 285 |
+
"rstrip": false,
|
| 286 |
+
"normalized": false,
|
| 287 |
+
"special": true
|
| 288 |
+
}
|
| 289 |
+
},
|
| 290 |
+
"chat_template": "{{ bos_token }}{%- macro format_parameters(properties, required, filter_keys=false) -%}\n {%- set standard_keys = ['description', 'type', 'properties', 'required', 'nullable'] -%}\n {%- set ns = namespace(found_first=false) -%}\n {%- for key, value in properties | dictsort -%}\n {%- set add_comma = false -%}\n {%- if not filter_keys or key not in standard_keys -%}\n {%- if ns.found_first %},{% endif -%}\n {%- set ns.found_first = true -%}\n {{ key }}:{\n {%- if value['description'] -%}\n description:<|\"|>{{ value['description'] }}<|\"|>\n {%- set add_comma = true -%}\n {%- endif -%}\n {%- if value['type'] | upper == 'STRING' -%}\n {%- if value['enum'] -%}\n {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}\n enum:{{ format_argument(value['enum']) }}\n {%- endif -%}\n {%- elif value['type'] | upper == 'ARRAY' -%}\n {%- if value['items'] is mapping and value['items'] -%}\n {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}\n items:{\n {%- set ns_items = namespace(found_first=false) -%}\n {%- for item_key, item_value in value['items'] | dictsort -%}\n {%- if item_value is not none -%}\n {%- if ns_items.found_first %},{% endif -%}\n {%- set ns_items.found_first = true -%}\n {%- if item_key == 'properties' -%}\n properties:{\n {%- if item_value is mapping -%}\n {{- format_parameters(item_value, value['items']['required'] | default([])) -}}\n {%- endif -%}\n }\n {%- elif item_key == 'required' -%}\n required:[\n {%- for req_item in item_value -%}\n <|\"|>{{- req_item -}}<|\"|>\n {%- if not loop.last %},{% endif -%}\n {%- endfor -%}\n ]\n {%- elif item_key == 'type' -%}\n {%- if item_value is string -%}\n type:{{ format_argument(item_value | upper) }}\n {%- else -%}\n type:{{ format_argument(item_value | map('upper') | list) }}\n {%- endif -%}\n {%- else -%}\n {{ item_key }}:{{ format_argument(item_value) }}\n {%- endif -%}\n {%- endif -%}\n {%- endfor -%}\n }\n {%- endif -%}\n {%- endif -%}\n {%- if value['nullable'] %}\n {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}\n nullable:true\n {%- endif -%}\n {%- if value['type'] | upper == 'OBJECT' -%}\n {%- if value['properties'] is defined and value['properties'] is mapping -%}\n {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}\n properties:{\n {{- format_parameters(value['properties'], value['required'] | default([])) -}}\n }\n {%- elif value is mapping -%}\n {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}\n properties:{\n {{- format_parameters(value, value['required'] | default([]), filter_keys=true) -}}\n }\n {%- endif -%}\n {%- if value['required'] -%}\n {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}\n required:[\n {%- for item in value['required'] | default([]) -%}\n <|\"|>{{- item -}}<|\"|>\n {%- if not loop.last %},{% endif -%}\n {%- endfor -%}\n ]\n {%- endif -%}\n {%- endif -%}\n {%- if add_comma %},{%- else -%} {%- set add_comma = true -%} {% endif -%}\n type:<|\"|>{{ value['type'] | upper }}<|\"|>}\n {%- endif -%}\n {%- endfor -%}\n{%- endmacro -%}\n{%- macro format_function_declaration(tool_data) -%}\n declaration:{{- tool_data['function']['name'] -}}{description:<|\"|>{{- tool_data['function']['description'] -}}<|\"|>\n {%- set params = tool_data['function']['parameters'] -%}\n {%- if params -%}\n ,parameters:{\n {%- if params['properties'] -%}\n properties:{ {{- format_parameters(params['properties'], params['required']) -}} },\n {%- endif -%}\n {%- if params['required'] -%}\n required:[\n {%- for item in params['required'] -%}\n <|\"|>{{- item -}}<|\"|>\n {{- ',' if not loop.last -}}\n {%- endfor -%}\n ],\n {%- endif -%}\n {%- if params['type'] -%}\n type:<|\"|>{{- params['type'] | upper -}}<|\"|>}\n {%- endif -%}\n {%- endif -%}\n {%- if 'response' in tool_data['function'] -%}\n {%- set response_declaration = tool_data['function']['response'] -%}\n ,response:{\n {%- if response_declaration['description'] -%}\n description:<|\"|>{{- response_declaration['description'] -}}<|\"|>,\n {%- endif -%}\n {%- if response_declaration['type'] | upper == 'OBJECT' -%}\n type:<|\"|>{{- response_declaration['type'] | upper -}}<|\"|>}\n {%- endif -%}\n {%- endif -%}\n }\n{%- endmacro -%}\n{%- macro format_argument(argument, escape_keys=True) -%}\n {%- if argument is none -%}\n {{- 'null' -}}\n {%- elif argument is string -%}\n {{- '<|\"|>' + argument + '<|\"|>' -}}\n {%- elif argument is boolean -%}\n {{- 'true' if argument else 'false' -}}\n {%- elif argument is mapping -%}\n {{- '{' -}}\n {%- set ns = namespace(found_first=false) -%}\n {%- for key, value in argument | dictsort -%}\n {%- if ns.found_first %},{% endif -%}\n {%- set ns.found_first = true -%}\n {%- if escape_keys -%}\n {{- '<|\"|>' + key + '<|\"|>' -}}\n {%- else -%}\n {{- key -}}\n {%- endif -%}\n :{{- format_argument(value, escape_keys=escape_keys) -}}\n {%- endfor -%}\n {{- '}' -}}\n {%- elif argument is sequence -%}\n {{- '[' -}}\n {%- for item in argument -%}\n {{- format_argument(item, escape_keys=escape_keys) -}}\n {%- if not loop.last %},{% endif -%}\n {%- endfor -%}\n {{- ']' -}}\n {%- else -%}\n {{- argument -}}\n {%- endif -%}\n{%- endmacro -%}\n{%- macro strip_thinking(text) -%}\n {%- set ns = namespace(result='') -%}\n {%- for part in text.split('<channel|>') -%}\n {%- if '<|channel>' in part -%}\n {%- set ns.result = ns.result + part.split('<|channel>')[0] -%}\n {%- else -%}\n {%- set ns.result = ns.result + part -%}\n {%- endif -%}\n {%- endfor -%}\n {{- ns.result | trim -}}\n{%- endmacro -%}\n{%- macro format_tool_response_block(tool_name, response) -%}\n {{- '<|tool_response>' -}}\n {%- if response is mapping -%}\n {{- 'response:' + tool_name + '{' -}}\n {%- for key, value in response | dictsort -%}\n {{- key -}}:{{- format_argument(value, escape_keys=False) -}}\n {%- if not loop.last %},{% endif -%}\n {%- endfor -%}\n {{- '}' -}}\n {%- else -%}\n {{- 'response:' + tool_name + '{value:' + format_argument(response, escape_keys=False) + '}' -}}\n {%- endif -%}\n {{- '<tool_response|>' -}}\n{%- endmacro -%}\n{%- set thinking = enable_thinking is defined and enable_thinking -%}\n{%- set loop_messages = messages -%}\n{%- if messages[0]['role'] in ['system', 'developer'] or thinking or (tools is defined and tools) -%}\n {{ '<|turn>system\n' }}\n {%- if thinking -%}\n {{ '<|think|>\n' }}\n {%- endif -%}\n {%- if messages[0]['role'] in ['system', 'developer'] -%}\n {%- if messages[0]['content'] is string -%}\n {{ messages[0]['content'] | trim }}\n {%- elif messages[0]['content'] is sequence -%}\n {%- for item in messages[0]['content'] -%}\n {{ item['text'] | trim + ' ' }}\n {%- endfor -%}\n {%- endif -%}\n {%- set loop_messages = messages[1:] -%}\n {%- endif -%}\n {%- if tools is defined and tools -%}\n {%- for tool in tools -%}\n {{- '<|tool>' + format_function_declaration(tool) | trim + '<tool|>' -}}\n {%- endfor -%}\n {%- endif -%}\n {{ '<turn|>\n' }}\n{%- endif -%}\n{%- set ns_turn = namespace(last_user_idx=-1) -%}\n{%- for m in loop_messages -%}{%- if m['role'] == 'user' -%}{%- set ns_turn.last_user_idx = loop.index0 -%}{%- endif -%}{%- endfor -%}\n{%- set ns_tool = namespace(turns=0, tool_calls=false, tool_response=false) -%}\n{%- for message in loop_messages -%}\n {%- if message['role'] != 'tool' -%}\n {%- set continues = message['role'] == 'assistant' and ns_tool.tool_calls -%}\n {%- if not continues and (message['role'] == 'user') != (ns_tool.turns % 2 == 0) -%}\n {{ raise_exception(\"Conversation roles must alternate user/assistant/user/assistant/...\") }}\n {%- endif -%}\n {%- if (message['role'] == 'assistant') -%}\n {%- set role = \"model\" -%}\n {%- else -%}\n {%- set role = message['role'] -%}\n {%- endif -%}\n {%- if not continues -%}\n {%- set ns_tool.turns = ns_tool.turns + 1 -%}\n {{ '<|turn>' + role + '\n' }}\n {%- endif -%}\n {%- if role == \"model\" -%}\n {%- set thinking_text = message.get('reasoning') or message.get('reasoning_content') -%}\n {%- if thinking_text and loop.index0 > ns_turn.last_user_idx -%}\n {{ '<|channel>thought\n' + thinking_text + '\n<channel|>' }}\n {%- endif -%}\n {%- endif -%}\n {%- set ns_tool.tool_calls = message.get('tool_calls') -%}\n {%- if ns_tool.tool_calls -%}\n {%- for tool_call in ns_tool.tool_calls -%}\n {%- set function = tool_call['function'] -%}\n {{- '<|tool_call>call:' + function['name'] + '{' -}}\n {%- if function['arguments'] is mapping -%}\n {%- set ns_args = namespace(found_first=false) -%}\n {%- for key, value in function['arguments'] | dictsort -%}\n {%- if ns_args.found_first %},{% endif -%}\n {%- set ns_args.found_first = true -%}\n {{- key -}}:{{- format_argument(value, escape_keys=False) -}}\n {%- endfor -%}\n {%- elif function['arguments'] is string -%}\n {%- set argstr = function['arguments'] | trim -%}\n {%- if argstr[:1] == '{' and argstr[-1:] == '}' -%}\n {{- argstr[1:-1] -}}\n {%- else -%}\n {{- function['arguments'] -}}\n {%- endif -%}\n {%- endif -%}\n {{- '}<tool_call|>' -}}\n {%- endfor -%}\n {%- set ns_tool.tool_response = false -%}\n {%- for tool_response in message.get('tool_responses') or [] -%}\n {{- format_tool_response_block(tool_response['name'] | default('unknown', true), tool_response['response']) -}}\n {%- set ns_tool.tool_response = true -%}\n {%- endfor -%}\n {%- set ns_scan = namespace(stopped=false, next_role=none) -%}\n {%- for k in range(loop.index0 + 1, loop_messages | length) -%}\n {%- if ns_scan.stopped -%}\n {%- elif loop_messages[k]['role'] != 'tool' -%}\n {%- set ns_scan.stopped = true -%}\n {%- set ns_scan.next_role = loop_messages[k]['role'] -%}\n {%- elif not message.get('tool_responses') -%}\n {%- set follow = loop_messages[k] -%}\n {%- set ns_tname = namespace(name=follow.get('name') or 'unknown') -%}\n {%- for tc in ns_tool.tool_calls -%}\n {%- if tc.get('id') == follow.get('tool_call_id') -%}\n {%- set ns_tname.name = tc['function']['name'] -%}\n {%- endif -%}\n {%- endfor -%}\n {%- set tool_body = follow.get('content') -%}\n {%- if tool_body is sequence and tool_body is not string and tool_body is not mapping -%}\n {%- set ns_txt = namespace(s='') -%}\n {%- for part in tool_body -%}\n {%- if part.get('type') == 'text' -%}\n {%- set ns_txt.s = ns_txt.s + (part.get('text') | default('')) -%}\n {%- endif -%}\n {%- endfor -%}\n {{- format_tool_response_block(ns_tname.name, ns_txt.s) -}}\n {%- for part in tool_body -%}\n {%- if part.get('type') in ['image', 'image_url'] -%}\n {{- '<|image|>' -}}\n {%- elif part.get('type') in ['audio', 'input_audio'] -%}\n {{- '<|audio|>' -}}\n {%- elif part.get('type') == 'video' -%}\n {{- '<|video|>' -}}\n {%- endif -%}\n {%- endfor -%}\n {%- else -%}\n {{- format_tool_response_block(ns_tname.name, tool_body) -}}\n {%- endif -%}\n {%- set ns_tool.tool_response = true -%}\n {%- endif -%}\n {%- endfor -%}\n {%- endif -%}\n {%- set captured_content -%}\n {%- if message['content'] is string -%}\n {%- if role == \"model\" -%}\n {{ strip_thinking(message['content']) }}\n {%- else -%}\n {{ message['content'] | trim }}\n {%- endif -%}\n {%- elif message['content'] is iterable -%}\n {%- for item in message['content'] -%}\n {%- if item['type'] == 'audio' -%}\n {{ '<|audio|>' }}\n {%- elif item['type'] == 'image' -%}\n {{ '<|image|>' }}\n {%- elif item['type'] == 'video' -%}\n {{ '<|video|>' }}\n {%- elif item['type'] == 'text' -%}\n {%- if role == \"model\" -%}\n {{ strip_thinking(item['text']) }}\n {%- else -%}\n {{ item['text'] | trim }}\n {%- endif -%}\n {%- endif -%}\n {%- endfor -%}\n {%- elif not ns_tool.tool_calls -%}\n {{ raise_exception(\"Invalid content type\") }}\n {%- endif -%}\n {%- endset -%}\n {{- captured_content -}}\n {%- if not ns_tool.tool_calls -%}\n {{ '<turn|>\n' }}\n {%- elif not ns_tool.tool_response -%}\n {{- '<|tool_response>' -}}\n {%- elif ns_scan.next_role != 'assistant' and (captured_content | trim | length > 0 or ns_scan.next_role) -%}\n {{- '<turn|>\n' -}}\n {%- set ns_tool.tool_calls = false -%}\n {%- endif -%}\n {%- endif -%}\n{%- endfor -%}\n{%- if add_generation_prompt -%}\n {%- if not ns_tool.tool_calls -%}\n {{'<|turn>model\n'}}\n {%- elif ns_tool.tool_response and thinking -%}\n {{- '<|channel>thought\n' -}}\n {%- endif -%}\n{%- endif -%}\n"
|
| 291 |
+
}
|