I wanna know more about ollama TEMPLATEs. I’ve read the whole doc but i can’t understand what’s going on. For example take a look at this template from mistral model:
{{- range $index, $_ := .Messages }}
{{- if eq .Role "user" }}
{{- if and (le (len (slice $.Messages $index)) 2) $.Tools }}[AVAILABLE_TOOLS] {{ json $.Tools }}[/AVAILABLE_TOOLS]
{{- end }}[INST] {{ if and (eq (len (slice $.Messages $index)) 1) $.System }}{{ $.System }}
{{ end }}{{ .Content }}[/INST]
{{- else if eq .Role "assistant" }}
{{- if .Content }} {{ .Content }}</s>
{{- else if .ToolCalls }}[TOOL_CALLS] [
{{- range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ json .Function.Arguments }}}
{{- end }}]</s>
{{- end }}
{{- else if eq .Role "tool" }}[TOOL_RESULTS] {"content": {{ .Content }}}[/TOOL_RESULTS]
{{- end }}
{{- end }}
what are {{ .System}} and {{ $.System}}?
are they pre-defined variables?
what about if-else? which condition do they check?
is len a pre defined function like len in python? how does it work?
what is [INST]?
PLEASE HELP ME
I’d be so happy if someone introduce me a good tutorial.
Thanks.
This link seems to be the official doc for ollama templates:
https://github.com/ollama/ollama/blob/main/docs/template.md
HMH is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.