juliendenize commited on
Commit
31f3753
·
verified ·
1 Parent(s): 7c3939a

Upload chat_template.jinja with huggingface_hub

Browse files
Files changed (1) hide show
  1. chat_template.jinja +6 -6
chat_template.jinja CHANGED
@@ -79,8 +79,8 @@
79
 
80
  {#- Assistant messages supports text content or text and image chunks. #}
81
  {%- elif message['role'] == 'assistant' %}
82
- {%- if message['content'] is not none and message['content'] | length > 0 and message['tool_calls'] is defined and message['tool_calls'] is not none and message['tool_calls'] | length > 0 %}
83
- {{- raise_exception('Assistant message cannot have both content and tool calls.') }}
84
  {%- endif %}
85
 
86
  {%- if message['content'] is string %}
@@ -93,7 +93,9 @@
93
  {{- raise_exception('Only text chunks are supported in assistant message contents.') }}
94
  {%- endif %}
95
  {%- endfor %}
96
- {%- elif message['tool_calls'] is defined and message['tool_calls'] is not none and message['tool_calls'] | length > 0 %}
 
 
97
  {%- for tool in message['tool_calls'] %}
98
  {%- set arguments = tool['function']['arguments'] %}
99
  {%- if arguments is not string %}
@@ -103,8 +105,6 @@
103
  {%- endif %}
104
  {{- '[TOOL_CALLS]' + tool['function']['name'] + '[ARGS]' + arguments }}
105
  {%- endfor %}
106
- {%- else %}
107
- {{- raise_exception('Assistant message must have a string or a list of chunks in content or a list of tool calls.') }}
108
  {%- endif %}
109
 
110
  {#- End of sequence token for each assistant messages. #}
@@ -116,6 +116,6 @@
116
 
117
  {#- Raise exception for unsupported roles. #}
118
  {%- else %}
119
- {{- raise_exception('Only user, assistant and tool roles are supported, got ' + message) }}
120
  {%- endif %}
121
  {%- endfor %}
 
79
 
80
  {#- Assistant messages supports text content or text and image chunks. #}
81
  {%- elif message['role'] == 'assistant' %}
82
+ {%- 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) %}
83
+ {{- raise_exception('Assistant message must have a string or a list of chunks in content or a list of tool calls.') }}
84
  {%- endif %}
85
 
86
  {%- if message['content'] is string %}
 
93
  {{- raise_exception('Only text chunks are supported in assistant message contents.') }}
94
  {%- endif %}
95
  {%- endfor %}
96
+ {%- endif %}
97
+
98
+ {%- if message['tool_calls'] is defined and message['tool_calls'] is not none and message['tool_calls']|length > 0 %}
99
  {%- for tool in message['tool_calls'] %}
100
  {%- set arguments = tool['function']['arguments'] %}
101
  {%- if arguments is not string %}
 
105
  {%- endif %}
106
  {{- '[TOOL_CALLS]' + tool['function']['name'] + '[ARGS]' + arguments }}
107
  {%- endfor %}
 
 
108
  {%- endif %}
109
 
110
  {#- End of sequence token for each assistant messages. #}
 
116
 
117
  {#- Raise exception for unsupported roles. #}
118
  {%- else %}
119
+ {{- raise_exception('Only user, assistant and tool roles are supported, got ' + message['role']) }}
120
  {%- endif %}
121
  {%- endfor %}