| {% for message in messages if message.role == 'user' and message.content is iterable and message.content is not string %} | |
| {% for item in message.content if item.type == 'image' %} | |
| {{- '<image>' -}} | |
| {% endfor %} | |
| {% endfor %} | |
| {{- '<|begin_of_sentence|>' -}} | |
| {%- set system_message = namespace(value=none) -%} | |
| {%- for message in messages if message.role == 'system' -%} | |
| {%- set system_message.value = message.content -%} | |
| {%- endfor -%} | |
| {%- if system_message.value -%} | |
| {{- system_message.value -}} | |
| {%- endif -%} | |
| {%- for message in messages -%} | |
| {%- if message.role == "user" -%} | |
| {{- '<|User|>' -}} | |
| {%- if message.content is string -%} | |
| {{- message.content -}} | |
| {%- elif message.content is iterable and message.content is not string -%} | |
| {%- for item in message.content if item.type == "text" -%} | |
| {{- item.text -}} | |
| {%- endfor -%} | |
| {%- endif -%} | |
| {%- elif message.role == "assistant" -%} | |
| {%- set thinking_tag = "" -%} | |
| {%- if enable_thinking is defined -%} | |
| {%- set thinking_tag = "</think>" if not enable_thinking else "<think>" -%} | |
| {%- endif -%} | |
| {{- '<|Assistant|>' + thinking_tag -}} | |
| {%- if message.content is string -%} | |
| {{- message.content -}} | |
| {%- elif message.content is iterable and message.content is not string -%} | |
| {%- for item in message.content if item.type == "text" -%} | |
| {{- item.text -}} | |
| {%- endfor -%} | |
| {%- endif -%} | |
| {{- '<|end_of_sentence|>' -}} | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {%- if add_generation_prompt -%} | |
| {{- '<|Assistant|>' -}} | |
| {%- if enable_thinking is defined -%} | |
| {{- "</think>" if not enable_thinking else "<think>" -}} | |
| {%- endif -%} | |
| {%- endif -%} |