Skip to content

Commit

Permalink
fix llama tool chat template error
Browse files Browse the repository at this point in the history
  • Loading branch information
LianxinGao committed Feb 8, 2025
1 parent 3243158 commit da9d9ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
19 changes: 11 additions & 8 deletions examples/tool_chat_template_llama3.1_json.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,19 @@
{%- endif %}
{{- '<|eot_id|>' }}
{%- elif 'tool_calls' in message %}
{%- if not message.tool_calls|length == 1 %}
{%- if message.tool_calls|length > 1 %}
{{- raise_exception("This model only supports single tool-calls at once!") }}
{%- elif message.tool_calls|length == 0 %}
{{- "No tool calls found." }}
{%- else %}
{%- set tool_call = message.tool_calls[0].function %}
{{- '<|start_header_id|>assistant<|end_header_id|>\n\n' -}}
{{- '{"name": "' + tool_call.name|trim + '", ' }}
{{- '"parameters": ' }}
{{- tool_call.arguments | tojson }}
{{- "}" }}
{{- "<|eot_id|>" }}
{%- endif %}
{%- set tool_call = message.tool_calls[0].function %}
{{- '<|start_header_id|>assistant<|end_header_id|>\n\n' -}}
{{- '{"name": "' + tool_call.name + '", ' }}
{{- '"parameters": ' }}
{{- tool_call.arguments | tojson }}
{{- "}" }}
{{- "<|eot_id|>" }}
{%- elif message.role == "tool" or message.role == "ipython" %}
{{- "<|start_header_id|>ipython<|end_header_id|>\n\n" }}
{%- if message.content is string %}
Expand Down
19 changes: 11 additions & 8 deletions examples/tool_chat_template_llama3.2_json.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,19 @@
{%- endif %}
{{- '<|eot_id|>' }}
{%- elif 'tool_calls' in message %}
{%- if not message.tool_calls|length == 1 %}
{%- if message.tool_calls|length > 1 %}
{{- raise_exception("This model only supports single tool-calls at once!") }}
{%- elif message.tool_calls|length == 0 %}
{{- "No tool calls found." }}
{%- else %}
{%- set tool_call = message.tool_calls[0].function %}
{{- '<|start_header_id|>assistant<|end_header_id|>\n\n' -}}
{{- '{"name": "' + tool_call.name|trim + '", ' }}
{{- '"parameters": ' }}
{{- tool_call.arguments | tojson }}
{{- "}" }}
{{- "<|eot_id|>" }}
{%- endif %}
{%- set tool_call = message.tool_calls[0].function %}
{{- '<|start_header_id|>assistant<|end_header_id|>\n\n' -}}
{{- '{"name": "' + tool_call.name + '", ' }}
{{- '"parameters": ' }}
{{- tool_call.arguments | tojson }}
{{- "}" }}
{{- "<|eot_id|>" }}
{%- elif message.role == "tool" or message.role == "ipython" %}
{{- "<|start_header_id|>ipython<|end_header_id|>\n\n" }}
{%- if message.content is string %}
Expand Down

0 comments on commit da9d9ac

Please sign in to comment.