Google gemma3 with added tools support.
vision
tools
4b
12b
27b
2,846 Pulls Updated 8 days ago
1ccc08e39a37 · 2.4kB
{{- /* System Prompt - Always at the beginning */ -}}
{{- if or .System .Tools }}
<start_of_turn>system
{{- if .System }}
{{ .System }}
{{- end }}
{{- if .Tools }}
You are a helpful assistant with tool-calling capabilities. You can also describe images.
When you receive a tool call response, use the output to format an answer to the original user question.
You only call tools when you need to get more information to reply.
Do not call tools unnecessarily, especially for introductory or basic questions.
{{- end }}
<end_of_turn>
{{- end }}
{{- /* Iterate through messages */ -}}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 }}
{{- /* User Messages */ -}}
{{- if eq .Role "user" }}
<start_of_turn>user
{{- /* Image Handling (for the LAST User Turn) */ -}}
{{- if and .Images $last }}
{{- range .Images }}
<image>
{{- /* Base64 image will go in, no need for additional quotes */ -}}
{{ . }}
</image>
{{- end }}
{{- end }}
{{- /* Tool Definitions (for the LAST User Turn) */ -}}
{{- if and $.Tools $last }}
Given the following functions, please respond with a JSON for a function call with its proper arguments that best answers the given prompt.
Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}. Do not use variables.
{{ range $.Tools }}
{{- . }}
{{ end }}
You must only call these tools: {{ range $i, $tool := $.Tools }}{{ if $i }}, {{ end }}`{{- $tool.Function.Name }}`{{ end }}.
You MUST NOT call ANY tool when responding to basic questions.
{{- end }}
{{ .Content }}<end_of_turn>
{{- /* Start Assistant Turn if it's the Last Message */ -}}
{{ if $last }}<start_of_turn>model
{{ end }}
{{- /* Assistant Messages */ -}}
{{- else if eq .Role "assistant" }}
<start_of_turn>model
{{- /* Tool Call JSON Output */ -}}
{{- if .ToolCalls }}
{{- range .ToolCalls }}
{"name": "{{ .Function.Name }}", "parameters": {{ .Function.Arguments }}}
{{- end }}
{{- else }}
{{ .Content }}
{{- end }}
{{- /* End Turn if Not the Last Message */ -}}
{{- if not $last }}<end_of_turn>
{{ end }}
{{- /* Tool Result Messages */ -}}
{{- else if eq .Role "tool" }}
<start_of_turn>user
Tool result:
{{ .Content }}<end_of_turn>
{{- /* Start Assistant Turn if it's the Last Message */ -}}
{{ if $last }}<start_of_turn>model
{{ end }}
{{- end }}
{{- end }}