Image-Text-to-Text
Transformers
Safetensors
llava
conversational

Working Ollama template

#16
by MobbyButcher - opened

After trying for hours, I've managed to make the model with this template that has been taken from Ollama repository's GGUF file:

Working template
{{- $reasoningPrompt := "You are a thoughtful, systematic AI assistant from ServiceNow Language Models (SLAM) lab. Analyze each question carefully, present your reasoning step-by-step, then provide the final response after the marker [BEGIN FINAL RESPONSE]." -}}

<|begin_system|>
{{ $reasoningPrompt }}
{{- if .System }}
{{ .System }}
{{- end }}
{{- if .Tools }}

You are provided with function signatures within <available_tools></available_tools> XML tags. You may call one or more functions to assist with the user query. Don't make assumptions about the arguments. You should infer the argument values from previous user responses and the system message. Here are the available tools:
<available_tools>
{{ .Tools }}
</available_tools>

Return all function calls as a list of JSON objects within <tool_calls></tool_calls> XML tags. Each JSON object should contain a function name and arguments as follows:
<tool_calls>[
    {"name": <function-name-1>, "arguments": <args-dict-1>}, 
    {"name": <function-name-2>, "arguments": <args-dict-2>},
    ...
]</tool_calls>
{{- end }}

{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 -}}

{{- if eq .Role "user" }}<|begin_user|>
{{ .Content }}{{ range .Images }}[IMG]{{ end }}
{{- end }}

{{- if eq .Role "assistant" }}

<|begin_assistant|>
{{- if .Content }}
{{ .Content }}
{{- end }}
{{- if .ToolCalls }}

<tool_calls>[{{ range $j, $tc := .ToolCalls }}{{ if $j }}, {{ end }}{"name": "{{ $tc.Function.Name }}", "arguments": {{ $tc.Function.Arguments }}{{ if $tc.ID }}, "id": "{{ $tc.ID }}"{{ end }}}{{ end }}]</tool_calls>
{{- end }}
{{- if not $last }}
<|end|>
{{ end }}
{{- end }}

{{- if false }}Here are my reasoning steps:
{{ .Thinking }}
[BEGIN FINAL RESPONSE]
{{ end }}

{{- if eq .Role "tool" }}
<|begin_tool_result|>
{{ .Content }}
{{ end }}

{{- if eq .Role "content" }}<|begin_content|>
{{ .Content }}
{{ end }}

{{- if and (ne .Role "assistant") $last }}

<|begin_assistant|>
Here are my reasoning steps:
{{ end }}

{{- end -}}

Usage:

  1. Download the GGUF you want to use, make sure it's somewhere you can find it.
  2. Create a new file (Modelfile, but you can use any name) with the following contents:
Modelfile
FROM ./model.gguf
TEMPLATE """{{- $reasoningPrompt := "You are a thoughtful, systematic AI assistant from ServiceNow Language Models (SLAM) lab. Analyze each question carefully, present your reasoning step-by-step, then provide the final response after the marker [BEGIN FINAL RESPONSE]." -}}

<|begin_system|>
{{ $reasoningPrompt }}
{{- if .System }}
{{ .System }}
{{- end }}
{{- if .Tools }}

You are provided with function signatures within <available_tools></available_tools> XML tags. You may call one or more functions to assist with the user query. Don't make assumptions about the arguments. You should infer the argument values from previous user responses and the system message. Here are the available tools:
<available_tools>
{{ .Tools }}
</available_tools>

Return all function calls as a list of JSON objects within <tool_calls></tool_calls> XML tags. Each JSON object should contain a function name and arguments as follows:
<tool_calls>[
    {"name": <function-name-1>, "arguments": <args-dict-1>}, 
    {"name": <function-name-2>, "arguments": <args-dict-2>},
    ...
]</tool_calls>
{{- end }}

{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 -}}

{{- if eq .Role "user" }}<|begin_user|>
{{ .Content }}{{ range .Images }}[IMG]{{ end }}
{{- end }}

{{- if eq .Role "assistant" }}

<|begin_assistant|>
{{- if .Content }}
{{ .Content }}
{{- end }}
{{- if .ToolCalls }}

<tool_calls>[{{ range $j, $tc := .ToolCalls }}{{ if $j }}, {{ end }}{"name": "{{ $tc.Function.Name }}", "arguments": {{ $tc.Function.Arguments }}{{ if $tc.ID }}, "id": "{{ $tc.ID }}"{{ end }}}{{ end }}]</tool_calls>
{{- end }}
{{- if not $last }}
<|end|>
{{ end }}
{{- end }}

{{- if false }}Here are my reasoning steps:
{{ .Thinking }}
[BEGIN FINAL RESPONSE]
{{ end }}

{{- if eq .Role "tool" }}
<|begin_tool_result|>
{{ .Content }}
{{ end }}

{{- if eq .Role "content" }}<|begin_content|>
{{ .Content }}
{{ end }}

{{- if and (ne .Role "assistant") $last }}

<|begin_assistant|>
Here are my reasoning steps:
{{ end }}

{{- end -}}"""
  1. Run ollama create Apriel-1.6-15B:Q4_K_M -f ./Modelfile

This should create a new model in Ollama.

Replace model path and name on the first line of your Modelfile (FROM ./model.gguf) to your model filename and path.
Replace model name (Apriel-1.6-15B:Q4_K_M) in ollama create Apriel-1.6-15B:Q4_K_M -f ./Modelfile command to whatever you want. I'd recommend keeping the same quantization tag (Q4_K_M) after the colon (:) as the quantization on your GGUF file, but it's not necessary.

Sign up or log in to comment