Unverified Commit ca04b97c authored by Rick Yuan's avatar Rick Yuan Committed by GitHub
Browse files

[Bugfix] Fix tool call template validation for Mistral models (#17644)


Signed-off-by: default avatarRick Yuan <yuan821120@gmail.com>
Signed-off-by: default avatarRIck Yuan <yuan821120@gmail.com>
Co-authored-by: default avatarAaron Pham <Aaronpham0103@gmail.com>
parent 0a9bbaa1
...@@ -29,7 +29,14 @@ ...@@ -29,7 +29,14 @@
{%- set user_messages = loop_messages | selectattr("role", "equalto", "user") | list %} {%- set user_messages = loop_messages | selectattr("role", "equalto", "user") | list %}
{%- for message in loop_messages | rejectattr("role", "equalto", "tool") | rejectattr("role", "equalto", "tool_results") | selectattr("tool_calls", "undefined") %} {%- set filtered_messages = [] %}
{%- for message in loop_messages %}
{%- if message["role"] not in ["tool", "tool_results"] and not message.get("tool_calls") %}
{%- set filtered_messages = filtered_messages + [message] %}
{%- endif %}
{%- endfor %}
{%- for message in filtered_messages %}
{%- if (message["role"] == "user") != (loop.index0 % 2 == 0) %} {%- if (message["role"] == "user") != (loop.index0 % 2 == 0) %}
{{- raise_exception("After the optional system message, conversation roles must alternate user/assistant/user/assistant/...") }} {{- raise_exception("After the optional system message, conversation roles must alternate user/assistant/user/assistant/...") }}
{%- endif %} {%- endif %}
...@@ -116,4 +123,4 @@ ...@@ -116,4 +123,4 @@
{%- else %} {%- else %}
{{- raise_exception("Only user and assistant roles are supported, with the exception of an initial optional system message!") }} {{- raise_exception("Only user and assistant roles are supported, with the exception of an initial optional system message!") }}
{%- endif %} {%- endif %}
{%- endfor %} {%- endfor %}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment