-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Misc] Provide correct Pixtral-HF chat template (#11891)
Signed-off-by: DarkLight1337 <[email protected]>
- Loading branch information
1 parent
bd82872
commit 9a22834
Showing
3 changed files
with
73 additions
and
27 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
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,38 @@ | ||
{%- if messages[0]["role"] == "system" %} | ||
{%- set system_message = messages[0]["content"] %} | ||
{%- set loop_messages = messages[1:] %} | ||
{%- else %} | ||
{%- set loop_messages = messages %} | ||
{%- endif %} | ||
|
||
{{- bos_token }} | ||
{%- for message in loop_messages %} | ||
{%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) %} | ||
{{- raise_exception('After the optional system message, conversation roles must alternate user/assistant/user/assistant/...') }} | ||
{%- endif %} | ||
{%- if message["role"] == "user" %} | ||
{%- if loop.last and system_message is defined %} | ||
{{- "[INST]" + system_message + "\n" }} | ||
{%- else %} | ||
{{- "[INST]" }} | ||
{%- endif %} | ||
{%- if message["content"] is not string %} | ||
{%- for chunk in message["content"] %} | ||
{%- if chunk["type"] == "text" %} | ||
{{- chunk["text"] }} | ||
{%- elif chunk["type"] == "image" %} | ||
{{- "[IMG]" }} | ||
{%- else %} | ||
{{- raise_exception("Unrecognized content type!") }} | ||
{%- endif %} | ||
{%- endfor %} | ||
{%- else %} | ||
{{- message["content"] }} | ||
{%- endif %} | ||
{{- "[/INST]" }} | ||
{%- elif message["role"] == "assistant" %} | ||
{{- message["content"] + eos_token}} | ||
{%- else %} | ||
{{- raise_exception("Only user and assistant roles are supported, with the exception of an initial optional system message!") }} | ||
{%- endif %} | ||
{%- endfor %} |
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