Update chat_template.jinja

#1
Files changed (1) hide show
  1. chat_template.jinja +14 -6
chat_template.jinja CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  {{- bos_token -}}
2
  {%- set preserve_thinking = preserve_thinking | default(false) -%}
3
 
@@ -34,11 +38,15 @@
34
  {%- for tool_call in tool_calls -%}
35
  {%- set func_name = tool_call["function"]["name"] -%}
36
  {%- set func_args = tool_call["function"]["arguments"] -%}
37
- {%- set args_ns = namespace(arg_strings=[]) -%}
38
- {%- for arg_name, arg_value in func_args.items() -%}
39
- {%- set args_ns.arg_strings = args_ns.arg_strings + [arg_name + "=" + format_arg_value(arg_value)] -%}
40
- {%- endfor -%}
41
- {%- set tool_calls_ns.tool_calls = tool_calls_ns.tool_calls + [func_name + "(" + (args_ns.arg_strings | join(", ")) + ")"] -%}
 
 
 
 
42
  {%- endfor -%}
43
  {{- "<|tool_call_start|>[" + (tool_calls_ns.tool_calls | join(", ")) + "]<|tool_call_end|>" -}}
44
  {%- endmacro -%}
@@ -95,7 +103,7 @@
95
  {{- content -}}
96
  {%- endif -%}
97
  {%- endif -%}
98
- {%- if message.tool_calls is defined -%}
99
  {{- render_tool_calls(message.tool_calls) -}}
100
  {%- endif -%}
101
  {%- if _has_cfm -%}
 
1
+ {#-
2
+ Modifications:
3
+ * Adding support for arguments as string so that minja does not detect the need to apply polyfills. This is dead path for OVMS as it always converts arguments to dict anyway.
4
+ #}
5
  {{- bos_token -}}
6
  {%- set preserve_thinking = preserve_thinking | default(false) -%}
7
 
 
38
  {%- for tool_call in tool_calls -%}
39
  {%- set func_name = tool_call["function"]["name"] -%}
40
  {%- set func_args = tool_call["function"]["arguments"] -%}
41
+ {%- if func_args is string -%}
42
+ {%- set tool_calls_ns.tool_calls = tool_calls_ns.tool_calls + [func_name + "(" + func_args + ")"] -%}
43
+ {%- else -%}
44
+ {%- set args_ns = namespace(arg_strings=[]) -%}
45
+ {%- for arg_name, arg_value in func_args.items() -%}
46
+ {%- set args_ns.arg_strings = args_ns.arg_strings + [arg_name + "=" + format_arg_value(arg_value)] -%}
47
+ {%- endfor -%}
48
+ {%- set tool_calls_ns.tool_calls = tool_calls_ns.tool_calls + [func_name + "(" + (args_ns.arg_strings | join(", ")) + ")"] -%}
49
+ {%- endif -%}
50
  {%- endfor -%}
51
  {{- "<|tool_call_start|>[" + (tool_calls_ns.tool_calls | join(", ")) + "]<|tool_call_end|>" -}}
52
  {%- endmacro -%}
 
103
  {{- content -}}
104
  {%- endif -%}
105
  {%- endif -%}
106
+ {%- if message.tool_calls is defined and message.tool_calls is iterable and message.tool_calls | length > 0 -%}
107
  {{- render_tool_calls(message.tool_calls) -}}
108
  {%- endif -%}
109
  {%- if _has_cfm -%}