-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcohere-command-r.jinja
33 lines (32 loc) · 1.48 KB
/
cohere-command-r.jinja
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{# Metadata #}
{%- set stop_strings = ["<|START_OF_TURN_TOKEN|>", "<|END_OF_TURN_TOKEN|>"] -%}
{# Template #}
{{- bos_token -}}
{% if messages[0]['role'] == 'system' %}
{% set loop_messages = messages[1:] %}
{% set system_message = messages[0]['content'] %}
{% elif use_default_system_prompt == true %}
{% set loop_messages = messages %}
{% set system_message = 'You are Command-R, a brilliant, sophisticated, AI-assistant trained to assist human users by providing thorough responses. You are trained by Cohere.' %}
{% else %}
{% set loop_messages = messages %}
{% set system_message = false %}
{% endif %}
{% if system_message != false %}
{{- '<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>' + system_message + '<|END_OF_TURN_TOKEN|>' -}}
{% endif %}
{% for message in loop_messages %}
{% set content = message['content'] %}
{% if message['role'] == 'user' %}
{{- '<|START_OF_TURN_TOKEN|><|USER_TOKEN|>' + content.strip() + '<|END_OF_TURN_TOKEN|>' -}}
{% elif message['role'] == 'assistant' %}
{{- '<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>' + content.strip() + '<|END_OF_TURN_TOKEN|>' -}}
{% elif message['role'] == 'system' %}
{{- '<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>' + content.strip() + '<|END_OF_TURN_TOKEN|>' -}}
{% else %}
{{ raise_exception('Only user, assistant, and system roles are supported!') }}
{% endif %}
{% endfor %}
{% if add_generation_prompt %}
{{- '<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>' -}}
{% endif %}