Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions extras/chat_template_examples/chat_template_gemma.jinja
Original file line number Diff line number Diff line change
@@ -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'] -%}
Expand Down Expand Up @@ -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) -}}
Expand Down Expand Up @@ -348,4 +345,4 @@
{{- '<|channel>thought\n<channel|>' -}}
{%- endif -%}
{%- endif -%}
{%- endif -%}
{%- endif -%}
16 changes: 5 additions & 11 deletions src/test/llm/chat_templates/chat_template_gemma.jinja
Original file line number Diff line number Diff line change
@@ -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) -%}
Expand Down Expand Up @@ -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) -%}
Expand Down Expand Up @@ -351,4 +345,4 @@
{{- '<|channel>thought\n<channel|>' -}}
{%- endif -%}
{%- endif -%}
{%- endif -%}
{%- endif -%}