cleanup, add chat template
Browse files- chat_template.jinja +131 -0
- preprocessor_config.json +0 -21
- processor_config.json +0 -63
- video_preprocessor_config.json +0 -21
chat_template.jinja
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- macro render_content(content, do_vision_count, is_system_content=false) %}
|
| 2 |
+
{%- if content is string %}
|
| 3 |
+
{{- content }}
|
| 4 |
+
{%- elif content is iterable and content is not mapping %}
|
| 5 |
+
{%- for item in content %}
|
| 6 |
+
{%- if 'text' in item %}
|
| 7 |
+
{{- item.text }}
|
| 8 |
+
{%- else %}
|
| 9 |
+
{{- raise_exception('Unexpected item type in content.') }}
|
| 10 |
+
{%- endif %}
|
| 11 |
+
{%- endfor %}
|
| 12 |
+
{%- elif content is none or content is undefined %}
|
| 13 |
+
{{- '' }}
|
| 14 |
+
{%- else %}
|
| 15 |
+
{{- raise_exception('Unexpected content type.') }}
|
| 16 |
+
{%- endif %}
|
| 17 |
+
{%- endmacro %}
|
| 18 |
+
{%- if not messages %}
|
| 19 |
+
{{- raise_exception('No messages provided.') }}
|
| 20 |
+
{%- endif %}
|
| 21 |
+
{%- if tools and tools is iterable and tools is not mapping %}
|
| 22 |
+
{{- '<|im_start|>system\n' }}
|
| 23 |
+
{{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
|
| 24 |
+
{%- for tool in tools %}
|
| 25 |
+
{{- "\n" }}
|
| 26 |
+
{{- tool | tojson }}
|
| 27 |
+
{%- endfor %}
|
| 28 |
+
{{- "\n</tools>" }}
|
| 29 |
+
{{- '\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>' }}
|
| 30 |
+
{%- if messages[0].role == 'system' %}
|
| 31 |
+
{%- set content = render_content(messages[0].content, false, true)|trim %}
|
| 32 |
+
{%- if content %}
|
| 33 |
+
{{- '\n\n' + content }}
|
| 34 |
+
{%- endif %}
|
| 35 |
+
{%- endif %}
|
| 36 |
+
{{- '<|im_end|>\n' }}
|
| 37 |
+
{%- else %}
|
| 38 |
+
{%- if messages[0].role == 'system' %}
|
| 39 |
+
{%- set content = render_content(messages[0].content, false, true)|trim %}
|
| 40 |
+
{{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}
|
| 41 |
+
{%- endif %}
|
| 42 |
+
{%- endif %}
|
| 43 |
+
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
|
| 44 |
+
{%- for message in messages[::-1] %}
|
| 45 |
+
{%- set index = (messages|length - 1) - loop.index0 %}
|
| 46 |
+
{%- if ns.multi_step_tool and message.role == "user" %}
|
| 47 |
+
{%- set content = render_content(message.content, false)|trim %}
|
| 48 |
+
{%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}
|
| 49 |
+
{%- set ns.multi_step_tool = false %}
|
| 50 |
+
{%- set ns.last_query_index = index %}
|
| 51 |
+
{%- endif %}
|
| 52 |
+
{%- endif %}
|
| 53 |
+
{%- endfor %}
|
| 54 |
+
{%- if ns.multi_step_tool %}
|
| 55 |
+
{{- raise_exception('No user query found in messages.') }}
|
| 56 |
+
{%- endif %}
|
| 57 |
+
{%- for message in messages %}
|
| 58 |
+
{%- set content = render_content(message.content, true)|trim %}
|
| 59 |
+
{%- if message.role == "system" %}
|
| 60 |
+
{%- if not loop.first %}
|
| 61 |
+
{{- raise_exception('System message must be at the beginning.') }}
|
| 62 |
+
{%- endif %}
|
| 63 |
+
{%- elif message.role == "user" %}
|
| 64 |
+
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
|
| 65 |
+
{%- elif message.role == "assistant" %}
|
| 66 |
+
{%- set reasoning_content = '' %}
|
| 67 |
+
{%- if message.reasoning_content is string %}
|
| 68 |
+
{%- set reasoning_content = message.reasoning_content %}
|
| 69 |
+
{%- else %}
|
| 70 |
+
{%- if '</think>' in content %}
|
| 71 |
+
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
|
| 72 |
+
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
|
| 73 |
+
{%- endif %}
|
| 74 |
+
{%- endif %}
|
| 75 |
+
{%- set reasoning_content = reasoning_content|trim %}
|
| 76 |
+
{%- if loop.index0 > ns.last_query_index %}
|
| 77 |
+
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
|
| 78 |
+
{%- else %}
|
| 79 |
+
{{- '<|im_start|>' + message.role + '\n' + content }}
|
| 80 |
+
{%- endif %}
|
| 81 |
+
{%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
|
| 82 |
+
{%- for tool_call in message.tool_calls %}
|
| 83 |
+
{%- if tool_call.function is defined %}
|
| 84 |
+
{%- set tool_call = tool_call.function %}
|
| 85 |
+
{%- endif %}
|
| 86 |
+
{%- if loop.first %}
|
| 87 |
+
{%- if content|trim %}
|
| 88 |
+
{{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 89 |
+
{%- else %}
|
| 90 |
+
{{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 91 |
+
{%- endif %}
|
| 92 |
+
{%- else %}
|
| 93 |
+
{{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
|
| 94 |
+
{%- endif %}
|
| 95 |
+
{%- if tool_call.arguments is mapping %}
|
| 96 |
+
{%- for args_name in tool_call.arguments %}
|
| 97 |
+
{%- set args_value = tool_call.arguments[args_name] %}
|
| 98 |
+
{{- '<parameter=' + args_name + '>\n' }}
|
| 99 |
+
{%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}
|
| 100 |
+
{{- args_value }}
|
| 101 |
+
{{- '\n</parameter>\n' }}
|
| 102 |
+
{%- endfor %}
|
| 103 |
+
{%- endif %}
|
| 104 |
+
{{- '</function>\n</tool_call>' }}
|
| 105 |
+
{%- endfor %}
|
| 106 |
+
{%- endif %}
|
| 107 |
+
{{- '<|im_end|>\n' }}
|
| 108 |
+
{%- elif message.role == "tool" %}
|
| 109 |
+
{%- if loop.previtem and loop.previtem.role != "tool" %}
|
| 110 |
+
{{- '<|im_start|>user' }}
|
| 111 |
+
{%- endif %}
|
| 112 |
+
{{- '\n<tool_response>\n' }}
|
| 113 |
+
{{- content }}
|
| 114 |
+
{{- '\n</tool_response>' }}
|
| 115 |
+
{%- if not loop.last and loop.nextitem.role != "tool" %}
|
| 116 |
+
{{- '<|im_end|>\n' }}
|
| 117 |
+
{%- elif loop.last %}
|
| 118 |
+
{{- '<|im_end|>\n' }}
|
| 119 |
+
{%- endif %}
|
| 120 |
+
{%- else %}
|
| 121 |
+
{{- raise_exception('Unexpected message role.') }}
|
| 122 |
+
{%- endif %}
|
| 123 |
+
{%- endfor %}
|
| 124 |
+
{%- if add_generation_prompt %}
|
| 125 |
+
{{- '<|im_start|>assistant\n' }}
|
| 126 |
+
{%- if enable_thinking is defined and enable_thinking is true %}
|
| 127 |
+
{{- '<think>\n' }}
|
| 128 |
+
{%- else %}
|
| 129 |
+
{{- '<think>\n\n</think>\n\n' }}
|
| 130 |
+
{%- endif %}
|
| 131 |
+
{%- endif %}
|
preprocessor_config.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"size": {
|
| 3 |
-
"longest_edge": 16777216,
|
| 4 |
-
"shortest_edge": 65536
|
| 5 |
-
},
|
| 6 |
-
"patch_size": 16,
|
| 7 |
-
"temporal_patch_size": 2,
|
| 8 |
-
"merge_size": 2,
|
| 9 |
-
"image_mean": [
|
| 10 |
-
0.5,
|
| 11 |
-
0.5,
|
| 12 |
-
0.5
|
| 13 |
-
],
|
| 14 |
-
"image_std": [
|
| 15 |
-
0.5,
|
| 16 |
-
0.5,
|
| 17 |
-
0.5
|
| 18 |
-
],
|
| 19 |
-
"processor_class": "Qwen3VLProcessor",
|
| 20 |
-
"image_processor_type": "Qwen2VLImageProcessorFast"
|
| 21 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
processor_config.json
DELETED
|
@@ -1,63 +0,0 @@
|
|
| 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 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
video_preprocessor_config.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"size": {
|
| 3 |
-
"longest_edge": 25165824,
|
| 4 |
-
"shortest_edge": 4096
|
| 5 |
-
},
|
| 6 |
-
"patch_size": 16,
|
| 7 |
-
"temporal_patch_size": 2,
|
| 8 |
-
"merge_size": 2,
|
| 9 |
-
"image_mean": [
|
| 10 |
-
0.5,
|
| 11 |
-
0.5,
|
| 12 |
-
0.5
|
| 13 |
-
],
|
| 14 |
-
"image_std": [
|
| 15 |
-
0.5,
|
| 16 |
-
0.5,
|
| 17 |
-
0.5
|
| 18 |
-
],
|
| 19 |
-
"processor_class": "Qwen3VLProcessor",
|
| 20 |
-
"video_processor_type": "Qwen3VLVideoProcessor"
|
| 21 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|