Gryphe commited on
Commit
eaea93a
·
verified ·
1 Parent(s): a616eb6

Update magistral_chat_template.jinja

Browse files
Files changed (1) hide show
  1. magistral_chat_template.jinja +7 -5
magistral_chat_template.jinja CHANGED
@@ -54,7 +54,7 @@
54
  {#- Handle conversation messages. #}
55
  {%- for message in loop_messages %}
56
 
57
- {#- User messages supports text content. #}
58
  {%- if message['role'] == 'user' %}
59
  {%- if message['content'] is string %}
60
  {{- '[INST]' + message['content'] + '[/INST]' }}
@@ -63,8 +63,10 @@
63
  {%- for block in message['content'] %}
64
  {%- if block['type'] == 'text' %}
65
  {{- block['text'] }}
 
 
66
  {%- else %}
67
- {{- raise_exception('Only text chunks are supported in user message content.') }}
68
  {%- endif %}
69
  {%- endfor %}
70
  {{- '[/INST]' }}
@@ -72,7 +74,7 @@
72
  {{- raise_exception('User message must have a string or a list of chunks in content') }}
73
  {%- endif %}
74
 
75
- {#- Assistant messages supports text content or text and thinking chunks. #}
76
  {%- elif message['role'] == 'assistant' %}
77
  {%- if (message['content'] is none or message['content'] == '' or message['content']|length == 0) and (message['tool_calls'] is not defined or message['tool_calls'] is none or message['tool_calls']|length == 0) %}
78
  {{- raise_exception('Assistant message must have a string or a list of chunks in content or a list of tool calls.') }}
@@ -108,7 +110,7 @@
108
 
109
  {{- eos_token }}
110
 
111
- {#- Tool messages only supports text content. #}
112
  {%- elif message['role'] == 'tool' %}
113
  {{- '[TOOL_RESULTS]' + message['content']|string + '[/TOOL_RESULTS]' }}
114
 
@@ -116,4 +118,4 @@
116
  {%- else %}
117
  {{- raise_exception('Only user, assistant and tool roles are supported, got ' + message['role'] + '.') }}
118
  {%- endif %}
119
- {%- endfor %}
 
54
  {#- Handle conversation messages. #}
55
  {%- for message in loop_messages %}
56
 
57
+ {#- User messages support text and image content. #}
58
  {%- if message['role'] == 'user' %}
59
  {%- if message['content'] is string %}
60
  {{- '[INST]' + message['content'] + '[/INST]' }}
 
63
  {%- for block in message['content'] %}
64
  {%- if block['type'] == 'text' %}
65
  {{- block['text'] }}
66
+ {%- elif block['type'] == 'image' or block['type'] == 'image_url' %}
67
+ {{- '[IMG]' }}
68
  {%- else %}
69
+ {{- raise_exception('Only text and image chunks are supported in user message content.') }}
70
  {%- endif %}
71
  {%- endfor %}
72
  {{- '[/INST]' }}
 
74
  {{- raise_exception('User message must have a string or a list of chunks in content') }}
75
  {%- endif %}
76
 
77
+ {#- Assistant messages support text content or text and thinking chunks. #}
78
  {%- elif message['role'] == 'assistant' %}
79
  {%- if (message['content'] is none or message['content'] == '' or message['content']|length == 0) and (message['tool_calls'] is not defined or message['tool_calls'] is none or message['tool_calls']|length == 0) %}
80
  {{- raise_exception('Assistant message must have a string or a list of chunks in content or a list of tool calls.') }}
 
110
 
111
  {{- eos_token }}
112
 
113
+ {#- Tool messages only support text content. #}
114
  {%- elif message['role'] == 'tool' %}
115
  {{- '[TOOL_RESULTS]' + message['content']|string + '[/TOOL_RESULTS]' }}
116
 
 
118
  {%- else %}
119
  {{- raise_exception('Only user, assistant and tool roles are supported, got ' + message['role'] + '.') }}
120
  {%- endif %}
121
+ {%- endfor %}