File size: 851 Bytes
a26cd09 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | {%- macro to_text(content) -%}
{%- if content is string -%}
{{- content -}}
{%- elif content is iterable and content is not mapping -%}
{%- for item in content -%}
{%- if item is mapping and item.type == 'text' and item.text is defined -%}
{{- item.text -}}
{%- elif item is mapping and (item.type == 'audio' or 'audio' in item) -%}
<|begin_of_audio|><|pad|><|end_of_audio|><|user|>
{% elif item is string -%}
{{- item -}}
{%- endif -%}
{%- endfor -%}
{%- else -%}
{{- content -}}
{%- endif -%}
{%- endmacro -%}
{%- for m in messages -%}
{%- if m.role == 'system' -%}
<|system|>
{{ to_text(m.content) | trim }}
{%- elif m.role == 'user' -%}
<|user|>
{{ to_text(m.content) | trim }}
{%- elif m.role == 'assistant' -%}
<|assistant|>
{{ to_text(m.content) | trim }}
{%- endif -%}
{%- endfor -%}
{%- if add_generation_prompt -%}
<|assistant|>
{% endif -%} |