tjtanaa's picture
fix llama-2 template
07a6749
raw
history blame
683 Bytes
{% if not add_generation_prompt is defined %}
{% set add_generation_prompt = false %}
{% endif %}
{% for message in messages %}
{% if message['role'] == 'user' %}
{% if loop.index0 % 2 == 1 and loop.index0 > 2 %}
{{ '<s>' + '[INST] ' + message['content'] + ' [/INST]' }}
{% elif loop.index0 % 2 == 1 and loop.index0 < 2 %}
{{ message['content'] + ' [/INST]' }}
{% elif loop.index0 % 2 == 0 %}
{{ '<s>' + '[INST] ' + message['content'] + ' [/INST]' }}
{% endif %}
{% elif message['role'] == 'system' %}
{{ '<s>[INST] <<SYS>>\n' + message['content'] + '\n<</SYS>>\n\n' }}
{% elif message['role'] == 'assistant' %}
{{ ' ' + message['content'] + ' ' + '</s>' }}
{% endif %}
{% endfor %}