llava.jinja 765 B

1234567891011121314151617181920212223
  1. {%- if messages[0]['role'] == 'system' -%}
  2. {%- set system_message = messages[0]['content'] -%}
  3. {%- set messages = messages[1:] -%}
  4. {%- else -%}
  5. {% set system_message = '' -%}
  6. {%- endif -%}
  7. {{ bos_token + system_message }}
  8. {%- for message in messages -%}
  9. {%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%}
  10. {{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}
  11. {%- endif -%}
  12. {%- if message['role'] == 'user' -%}
  13. {{ 'USER: ' + message['content'] + '\n' }}
  14. {%- elif message['role'] == 'assistant' -%}
  15. {{ 'ASSISTANT: ' + message['content'] + eos_token + '\n' }}
  16. {%- endif -%}
  17. {%- endfor -%}
  18. {%- if add_generation_prompt -%}
  19. {{ 'ASSISTANT:' }}
  20. {% endif %}