Update to Chat Template for .items() collision w/ user dicts.

#8
by Bennybo - opened
Files changed (1) hide show
  1. chat_template.jinja +6 -4
chat_template.jinja CHANGED
@@ -18,7 +18,8 @@
18
  {%- endif %}
19
  {{- '<tool_call>\n<function=' + (tool_call.name | default('') | string) + '>\n' }}
20
  {%- if tool_call.arguments is defined and tool_call.arguments is mapping %}
21
- {%- for args_name, args_value in tool_call.arguments.items() %}
 
22
  {{- '<parameter=' + (args_name | string) + '>\n' }}
23
  {%- if args_value is mapping or (args_value is sequence and args_value is not string) %}
24
  {{- args_value | tojson | safe }}
@@ -62,8 +63,9 @@
62
  {{- '\n<description>' ~ (tool.description | string | trim) ~ '</description>' }}
63
  {%- endif %}
64
  {{- '\n<parameters>' }}
65
- {%- if tool.parameters is defined and tool.parameters is mapping and tool.parameters.properties is defined and tool.parameters.properties is mapping %}
66
- {%- for param_name, param_fields in tool.parameters.properties.items() %}
 
67
  {{- '\n<parameter>\n<name>' ~ (param_name | string) ~ '</name>' }}
68
  {%- if param_fields is mapping and param_fields.type is defined and param_fields.type is not none %}
69
  {{- '\n<type>' ~ (param_fields.type | string) ~ '</type>' }}
@@ -156,4 +158,4 @@
156
 
157
  {%- if add_generation_prompt %}
158
  {{- '<|im_start|>assistant\n<think>' }}
159
- {%- endif %}
 
18
  {%- endif %}
19
  {{- '<tool_call>\n<function=' + (tool_call.name | default('') | string) + '>\n' }}
20
  {%- if tool_call.arguments is defined and tool_call.arguments is mapping %}
21
+ {%- for args_name in tool_call.arguments %}
22
+ {%- set args_value = tool_call.arguments[args_name] %}
23
  {{- '<parameter=' + (args_name | string) + '>\n' }}
24
  {%- if args_value is mapping or (args_value is sequence and args_value is not string) %}
25
  {{- args_value | tojson | safe }}
 
63
  {{- '\n<description>' ~ (tool.description | string | trim) ~ '</description>' }}
64
  {%- endif %}
65
  {{- '\n<parameters>' }}
66
+ {%- if tool.parameters is defined and tool.parameters is mapping and 'properties' in tool.parameters and tool.parameters['properties'] is mapping %}
67
+ {%- for param_name in tool.parameters['properties'] %}
68
+ {%- set param_fields = tool.parameters['properties'][param_name] %}
69
  {{- '\n<parameter>\n<name>' ~ (param_name | string) ~ '</name>' }}
70
  {%- if param_fields is mapping and param_fields.type is defined and param_fields.type is not none %}
71
  {{- '\n<type>' ~ (param_fields.type | string) ~ '</type>' }}
 
158
 
159
  {%- if add_generation_prompt %}
160
  {{- '<|im_start|>assistant\n<think>' }}
161
+ {%- endif %}