fix: update argument extraction in R1 chat template (#15547)
Signed-off-by: Xinyuan Tong <xinyuantong.cs@gmail.com>
This commit is contained in:
@@ -51,15 +51,17 @@
|
|||||||
{%- set ns.is_tool = false -%}
|
{%- set ns.is_tool = false -%}
|
||||||
{%- set ns.is_output_first = true %}
|
{%- set ns.is_output_first = true %}
|
||||||
{%- for tool in message['tool_calls'] %}
|
{%- for tool in message['tool_calls'] %}
|
||||||
|
{%- set tool_type = tool['type'] if tool['type'] is defined else 'function' -%}
|
||||||
|
{%- set tool_args = tool['function']['arguments'] if tool['function']['arguments'] is string else tool['function']['arguments'] | tojson -%}
|
||||||
{%- if not ns.is_first %}
|
{%- if not ns.is_first %}
|
||||||
{%- if content is none %}
|
{%- if content is none %}
|
||||||
{{'<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] + '\n' + '```' + '<|tool▁call▁end|>'}}
|
{{'<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool_type + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool_args + '\n' + '```' + '<|tool▁call▁end|>'}}
|
||||||
{%- else %}
|
{%- else %}
|
||||||
{{content + '<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] + '\n' + '```' + '<|tool▁call▁end|>'}}
|
{{content + '<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool_type + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool_args + '\n' + '```' + '<|tool▁call▁end|>'}}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- set ns.is_first = true -%}
|
{%- set ns.is_first = true -%}
|
||||||
{%- else %}
|
{%- else %}
|
||||||
{{'\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] + '\n' + '```' + '<|tool▁call▁end|>'}}
|
{{'\n' + '<|tool▁call▁begin|>' + tool_type + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool_args + '\n' + '```' + '<|tool▁call▁end|>'}}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
{{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}
|
{{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}
|
||||||
|
|||||||
Reference in New Issue
Block a user