diff --git a/extras/chat_template_examples/chat_template_gemma.jinja b/extras/chat_template_examples/chat_template_gemma.jinja index 385214b197..55f02f1a44 100644 --- a/extras/chat_template_examples/chat_template_gemma.jinja +++ b/extras/chat_template_examples/chat_template_gemma.jinja @@ -1,7 +1,6 @@ {#- Modifications to original chat template: * Ignoring "response" field from tool definition (it was broken, but also it is inline now with other servings) - * Whenever template renders tool_call arguments, those are converted from string to dictlike format using from_json #} {%- macro format_parameters(properties, required, filter_keys=false) -%} {%- set standard_keys = ['description', 'type', 'properties', 'required', 'nullable'] -%} @@ -237,13 +236,11 @@ {%- if message['tool_calls'] -%} {%- for tool_call in message['tool_calls'] -%} - {#- Patch: Usage of from_json to convert tool_call arguments from string to dictlike #} {%- set function = tool_call['function'] -%} - {%- set args = function['arguments'] | from_json -%} {{- '<|tool_call>call:' + function['name'] + '{' -}} - {%- if args is mapping -%} + {%- if function['arguments'] is mapping -%} {%- set ns_args = namespace(found_first=false) -%} - {%- for key, value in args | dictsort -%} + {%- for key, value in function['arguments'] | dictsort -%} {%- if ns_args.found_first %},{% endif -%} {%- set ns_args.found_first = true -%} {{- key -}}:{{- format_argument(value, escape_keys=False) -}} @@ -348,4 +345,4 @@ {{- '<|channel>thought\n' -}} {%- endif -%} {%- endif -%} -{%- endif -%} \ No newline at end of file +{%- endif -%} diff --git a/src/test/llm/chat_templates/chat_template_gemma.jinja b/src/test/llm/chat_templates/chat_template_gemma.jinja index f62ca843a4..55f02f1a44 100644 --- a/src/test/llm/chat_templates/chat_template_gemma.jinja +++ b/src/test/llm/chat_templates/chat_template_gemma.jinja @@ -1,3 +1,7 @@ +{#- + Modifications to original chat template: + * Ignoring "response" field from tool definition (it was broken, but also it is inline now with other servings) +#} {%- macro format_parameters(properties, required, filter_keys=false) -%} {%- set standard_keys = ['description', 'type', 'properties', 'required', 'nullable'] -%} {%- set ns = namespace(found_first=false) -%} @@ -103,16 +107,6 @@ type:<|"|>{{- params['type'] | upper -}}<|"|>} {%- endif -%} {%- endif -%} - {%- if 'response' in tool_data['function'] -%} - {%- set response_declaration = tool_data['function']['response'] -%} - ,response:{ - {%- if response_declaration['description'] -%} - description:<|"|>{{- response_declaration['description'] -}}<|"|>, - {%- endif -%} - {%- if response_declaration['type'] | upper == 'OBJECT' -%} - type:<|"|>{{- response_declaration['type'] | upper -}}<|"|>} - {%- endif -%} - {%- endif -%} } {%- endmacro -%} {%- macro format_argument(argument, escape_keys=True) -%} @@ -351,4 +345,4 @@ {{- '<|channel>thought\n' -}} {%- endif -%} {%- endif -%} -{%- endif -%} \ No newline at end of file +{%- endif -%}