-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Boris Shaposhnikov
committed
Oct 15, 2024
1 parent
c89301a
commit efd99a7
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{%- set replica_start = ['<start_of_turn>'] -%} | ||
{%- set replica_end = ['<end_of_turn>'] -%} | ||
|
||
{%- if messages[0]['role'] == 'system' %} | ||
{%- set system_message = messages[0]['content'] | trim + '\n\n' %} | ||
{%- set messages = messages[1:] %} | ||
{%- else %} | ||
{%- set system_message = '' %} | ||
{%- endif %} | ||
|
||
{%- for message in messages %} | ||
{%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) %} | ||
{{- raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }} | ||
{%- endif %} | ||
|
||
{%- if loop.index0 == 0 %} | ||
{%- set content = system_message + message['content'] %} | ||
{%- else %} | ||
{%- set content = message['content'] %} | ||
{%- endif %} | ||
|
||
{%- if (message['role'] == 'bot') %} | ||
{{- '<start_of_turn>' + message['role'] + '\n'}} | ||
{%- generation %} | ||
{{- content | trim + '<end_of_turn>' }} | ||
{%- endgeneration %} | ||
{%- else %} | ||
{{- '<start_of_turn>' + message['role'] + '\n' + content | trim + '<end_of_turn>' }} | ||
{%- endif %} | ||
{%- endfor %} | ||
|
||
{%- if add_generation_prompt %} | ||
{{- '<start_of_turn>model\n' }} | ||
{%- endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{%- set replica_start = ['<|start_header_id|>'] -%} | ||
{%- set replica_end = ['<|eot_id|>'] -%} | ||
{{- '<|begin_of_text|>' -}} | ||
|
||
{%- for message in messages -%} | ||
{%- if (message['role'] != 'bot') %} | ||
{{- '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] + '<|eot_id|>' -}} | ||
{%- elif (message['role'] == 'bot') %} | ||
{{- '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' -}} | ||
{%- generation %} | ||
{{- message['content'] + '<|eot_id|>' -}} | ||
{%- endgeneration %} | ||
{%- endif -%} | ||
{%- endfor -%} | ||
|
||
{%- if add_generation_prompt -%} | ||
{{- '<|start_header_id|>' + 'bot' + '<|end_header_id|>\n\n' -}} | ||
{%- endif -%} |