64 lines
2.5 KiB
Django/Jinja
64 lines
2.5 KiB
Django/Jinja
{{ bos_token }}
|
|
{%- if messages[0]['role'] == 'system' -%}
|
|
{%- if messages[0]['content'] is string -%}
|
|
{%- set first_user_prefix = messages[0]['content'] + '\n\n' -%}
|
|
{%- else -%}
|
|
{%- set first_user_prefix = messages[0]['content'][0]['text'] + '\n\n' -%}
|
|
{%- endif -%}
|
|
{%- set loop_messages = messages[1:] -%}
|
|
{%- else -%}
|
|
{%- set first_user_prefix = "You are a helpful AI Assistant that provides well-reasoned and detailed responses. You first think about the reasoning process as an internal monologue and then provide the user with the answer. Respond in the following format: <think>
|
|
...
|
|
</think>
|
|
<answer>
|
|
...
|
|
</answer>\n\n" -%}
|
|
{%- set loop_messages = messages -%}
|
|
{%- endif -%}
|
|
{%- for message in loop_messages -%}
|
|
{%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%}
|
|
{{ raise_exception("Conversation roles must alternate user/assistant/user/assistant/...") }}
|
|
{%- endif -%}
|
|
{%- if (message['role'] == 'assistant') -%}
|
|
{%- set role = "model" -%}
|
|
{%- else -%}
|
|
{%- set role = message['role'] -%}
|
|
{%- endif -%}
|
|
{{ '<start_of_turn>' + role + '\n' + (first_user_prefix if loop.first else "") }}
|
|
{%- if message['role'] == 'assistant' -%}
|
|
{% generation %}
|
|
{%- if message['content'] is string -%}
|
|
{{ message['content'] | trim }}
|
|
{%- elif message['content'] is iterable -%}
|
|
{%- for item in message['content'] -%}
|
|
{%- if item['type'] == 'image' -%}
|
|
{{ '<start_of_image>' }}
|
|
{%- elif item['type'] == 'text' -%}
|
|
{{ item['text'] | trim }}
|
|
{%- endif -%}
|
|
{%- endfor -%}
|
|
{%- else -%}
|
|
{{ raise_exception("Invalid content type") }}
|
|
{%- endif -%}
|
|
{{ '<end_of_turn>\n' }}
|
|
{% endgeneration %}
|
|
{%- else -%}
|
|
{%- if message['content'] is string -%}
|
|
{{ message['content'] | trim }}
|
|
{%- elif message['content'] is iterable -%}
|
|
{%- for item in message['content'] -%}
|
|
{%- if item['type'] == 'image' -%}
|
|
{{ '<start_of_image>' }}
|
|
{%- elif item['type'] == 'text' -%}
|
|
{{ item['text'] | trim }}
|
|
{%- endif -%}
|
|
{%- endfor -%}
|
|
{%- else -%}
|
|
{{ raise_exception("Invalid content type") }}
|
|
{%- endif -%}
|
|
{{ '<end_of_turn>\n' }}
|
|
{%- endif -%}
|
|
{%- endfor -%}
|
|
{%- if add_generation_prompt -%}
|
|
{{'<start_of_turn>model\n'}}
|
|
{%- endif -%} |