diff --git a/src/axolotl/utils/chat_templates/templates/qwen3_5.jinja b/src/axolotl/utils/chat_templates/templates/qwen3_5.jinja index 21f5733ed..c8d0e8da0 100644 --- a/src/axolotl/utils/chat_templates/templates/qwen3_5.jinja +++ b/src/axolotl/utils/chat_templates/templates/qwen3_5.jinja @@ -1,7 +1,19 @@ {%- if tools %} {{- '<|im_start|>system\n' }} {%- if messages[0].role == 'system' %} - {{- messages[0].content + '\n\n' }} + {%- if messages[0].content is string %} + {{- messages[0].content + '\n\n' }} + {%- else %} + {%- for part in messages[0].content %} + {%- if part is mapping %} + {%- set system_text = part.get('text') or part.get('content') or part.get('value') %} + {%- if system_text %}{{- system_text }}{%- endif %} + {%- elif part is string %} + {{- part }} + {%- endif %} + {%- endfor %} + {{- '\n\n' }} + {%- endif %} {%- endif %} {{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within XML tags:\n" }} {%- for tool in tools %} @@ -11,7 +23,20 @@ {{- "\n\n\nFor each function call, return a json object with function name and arguments within XML tags:\n\n{\"name\": , \"arguments\": }\n<|im_end|>\n" }} {%- else %} {%- if messages[0].role == 'system' %} - {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }} + {%- if messages[0].content is string %} + {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }} + {%- else %} + {{- '<|im_start|>system\n' }} + {%- for part in messages[0].content %} + {%- if part is mapping %} + {%- set system_text = part.get('text') or part.get('content') or part.get('value') %} + {%- if system_text %}{{- system_text }}{%- endif %} + {%- elif part is string %} + {{- part }} + {%- endif %} + {%- endfor %} + {{- '<|im_end|>\n' }} + {%- endif %} {%- endif %} {%- endif %} {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}