ZONOS3-Mini-transformers / chat_template.jinja
Gatozu35's picture
ZONOS3-Mini for native transformers (zonos3_mini)
3f582bf verified
Raw History Blame Contribute Delete
1.16 kB
{%- set training = messages | length == 2 -%}
{%- if messages | length > 2 or messages[0]['role'] != 'user' or (training and messages[1]['role'] != 'assistant') -%}
{{- raise_exception('ZONOS3-Mini takes one `user` message per conversation, optionally followed by the `assistant` target audio to train on.') -}}
{%- endif -%}
{%- if training -%}
{%- set target = messages[1]['content'] -%}
{%- if target is string or target | length != 1 or target[0]['type'] != 'audio' -%}
{{- raise_exception('The `assistant` turn holds one `audio` item, the target.') -}}
{%- endif -%}
{%- endif -%}
{%- set content = messages[0]['content'] -%}
{%- if content is string -%}
{%- set texts = [content] -%}
{%- set num_audio = 0 -%}
{%- else -%}
{%- set texts = content | selectattr('type', 'equalto', 'text') | map(attribute='text') | list -%}
{%- set num_audio = content | selectattr('type', 'equalto', 'audio') | list | length -%}
{%- endif -%}
{%- if texts | length != 1 or num_audio > 1 -%}
{{- raise_exception('The `user` turn holds one `text` item and at most one `audio` item (the voice).') -}}
{%- endif -%}
{{- texts[0] -}}