| {%- macro visible_text(content) -%} | |
| {%- if content is iterable and content is not mapping -%} | |
| {%- for item in content -%} | |
| {%- if item is mapping and item.type == "text" -%} | |
| {{- item.text -}} | |
| {%- elif item is string -%} | |
| {{- item -}} | |
| {%- endif -%} | |
| {%- endfor -%} | |
| {%- else -%} | |
| {{- content -}} | |
| {%- endif -%} | |
| {%- endmacro -%} | |
| {%- for message in messages -%} | |
| {%- if loop.first and messages[0].role != "system" -%} | |
| {{- "<|im_start|>system\nYou are Ami, a helpful, friendly and empathetic AI chatbot.<|im_end|>\n" -}} | |
| {%- endif -%} | |
| {{- "<|im_start|>" + message.role + "\n" + visible_text(message.content) + "<|im_end|>\n" -}} | |
| {%- endfor -%} | |
| {%- if add_generation_prompt -%} | |
| {{- "<|im_start|>assistant\n" -}} | |
| {%- endif -%} |