{%- for message in messages -%} | |
{%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%} | |
{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }} | |
{%- endif -%} | |
{%- if message['role'] == 'user' -%} | |
{{ '<问>:' + message['content'] + '\n' }} | |
{%- elif message['role'] == 'assistant' -%} | |
{{ '<答>:' + message['content'] + '\n' }} | |
{%- endif -%} | |
{%- endfor -%} | |
{%- if add_generation_prompt -%} | |
{{- '<答>:' -}} | |
{% endif %} |