1,053 8 months ago

Gemma 2 with tool call support

tools 2b 9b 27b
34fdbc62ccfa · 1.4kB
{{- if or .System .Tools }}<start_of_turn>system
{{- if .System }}
{{ .System }}
{{- end }}
{{- if .Tools }}
When you receive a tool call response, use the output to format an answer to the original user question.
You are a helpful assistant with tool-calling capabilities. You only call tools when you need to get more information to reply.
{{- end }}
{{- end }}<end_of_turn>
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 }}
{{- if eq .Role "user" }}<start_of_turn>user
{{- 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 }}
{{- end }}
{{ .Content }}<end_of_turn>{{ if $last }}<start_of_turn>assistant
{{ end }}
{{- else if eq .Role "assistant" }}<start_of_turn>assistant
{{- if .ToolCalls }}
{{- range .ToolCalls }}{"name": "{{ .Function.Name }}", "parameters": {{ .Function.Arguments }}}{{ end }}
{{- else }}
{{ .Content }}{{ if not $last }}<end_of_turn>{{ end }}
{{- end }}
{{- else if eq .Role "tool" }}<start_of_turn>system
Tool result:
{{ .Content }}<end_of_turn>{{ if $last }}<start_of_turn>assistant
{{ end }}
{{- end }}
{{- end }}