{{- /* 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, such as "who are you?", "introduce yourself", "what is your name?" or variations of such questions.
Every tool call is very precious and will cost a lot of money, so please do not call tools too often.
{{- 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 questions like "who are you?", "introduce yourself", "what is your name?", or any variations of these questions.
{{- end }}
{{ .Content }}<end_of_turn>
{{- /* Start Assistant Turn if it's the Last Message */ -}}