153 1 month ago

vision tools 1b 4b 12b 27b
03c1a69e4e61 · 2.1kB
{{- $lastUserIdx := -1 -}}
{{- range $idx, $msg := .Messages -}}
{{- if eq $msg.Role "user" }}{{ $lastUserIdx = $idx }}{{ end -}}
{{- end }}
{{- if or .System .Tools }}<start_of_turn>system
{{- if .System }}
{{ .System }}
{{- end }}
{{- if .Tools }}
{{- /* Tool Calling instruction is from this gemma3 official document */ -}}
{{- /* https://ai.google.dev/gemma/docs/capabilities/function-calling?hl=ja#function-calling-setup */ -}}
You have access to following functions,
{{- /* Tool List */ -}}
{{- range .Tools }}
{{- . }}
{{ end }}
If you decide to invoke any of the function(s),
You MUST output only raw XML tags for function calls.
DO NOT wrap the output in any Markdown formatting (like triple backticks: ``` or ```xml).
<tool_call>
{"name": "function_name", "arguments": {"arg1": "value1", "arg2": "value2"}}
</tool_call>
❌ Incorrect:
```xml
<tool_call>
...
</tool_call>
You SHOULD NOT include any other text in the response if you call functions.
If you have function reseponse in <tool_output></tool_output> XML tags. Please use them and answer query or request further function call.
{{- end }}{{- /* End of tool calling instruction */ -}}
<end_of_turn>
{{ end }}{{- /* rnd if or .System .Tools */ -}}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
{{- /* 1. user */ -}}
{{- if eq .Role "user" }}<start_of_turn>user
{{ .Content }}<end_of_turn>
{{- /* 2. assistant */ -}}
{{- else if eq .Role "assistant" }}<start_of_turn>model
{{- if .Content }}
{{ .Content }}
{{- /* if model call tool */ -}}
{{- else if .ToolCalls }}<tool_call>
{{- range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
{{ end }}
</tool_call>
{{- end }}
{{- if not $last }}
<end_of_turn>
{{- end }}
{{- /* 3. tool */ -}}
{{- else if eq .Role "tool" }}<start_of_turn>user
<tool_output>
{{ .Content }}
</tool_output><end_of_turn>
{{- end }}
{{- /* if last message isn't assistant, add start token for assistant */ -}}
{{- if and (ne .Role "assistant") $last }}<start_of_turn>model
{{- end }}
{{- end }}