From 885e5b459432c499ca5bf43e6f8fc981fb246ff1 Mon Sep 17 00:00:00 2001 From: Kyle Mistele Date: Fri, 6 Sep 2024 21:49:01 -0500 Subject: [PATCH] [Bugfix] Fix Hermes tool call chat template bug (#8256) Co-authored-by: Kyle Mistele Signed-off-by: Amit Garg --- examples/tool_chat_template_hermes.jinja | 31 ++++++++++++------------ 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/examples/tool_chat_template_hermes.jinja b/examples/tool_chat_template_hermes.jinja index b18b463032d4f..0b0902c8e7497 100644 --- a/examples/tool_chat_template_hermes.jinja +++ b/examples/tool_chat_template_hermes.jinja @@ -89,22 +89,23 @@ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }} {%- elif message.role == "assistant" and message.tool_calls is defined %} {{- '<|im_start|>' + message.role }} - {%- for tool_call in message.tool_calls %} - {{- '\n\n' }} - {%- if tool_call.function is defined %} - {%- set tool_call = tool_call.function %} - {%- endif %} - {{- '{' }} - {{- '"name": "' }} - {{- tool_call.name }} - {{- '"}' }} + {%- for tool_call in message.tool_calls %} + {{- '\n\n' }} + {%- if tool_call.function is defined %} + {%- set tool_call = tool_call.function %} + {%- endif %} + {{- '{' }} + {{- '"name": "' }} + {{- tool_call.name }} + {{- '"' }} + {%- if tool_call.arguments is defined %} {{- ', ' }} - {%- if tool_call.arguments is defined %} - {{- '"arguments": ' }} - {{- tool_call.arguments|tojson }} - {%- endif %} - {{- '\n' }} - {%- endfor %} + {{- '"arguments": ' }} + {{- tool_call.arguments|tojson }} + {%- endif %} + {{- '}' }} + {{- '\n' }} + {%- endfor %} {{- '<|im_end|>\n' }} {%- elif message.role == "tool" %} {%- if loop.previtem and loop.previtem.role != "tool" %}