Skip to content

Commit 3dc134f

Browse files
committed
ollama update 2025-10-06
1 parent 10c5429 commit 3dc134f

File tree

1 file changed

+64
-13
lines changed

1 file changed

+64
-13
lines changed

packages/ollama-utils/src/chat-template-automap.ts

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,54 @@ import type { OllamaChatTemplateMapEntry } from "./types";
55

66
/**
77
* Skipped these models due to error:
8-
* - library/llama3.3:latest
9-
* - library/llama3.2-vision:latest
8+
* - library/qwen:latest
9+
* - library/gpt-oss:latest
10+
* - library/gemma2:latest
11+
* - library/qwen:0.5b
12+
* - library/minicpm-v:latest
13+
* - library/gemma3:latest
14+
* - library/deepseek-v3.1:latest
15+
* - library/deepseek-v3.1:latest
16+
* - library/gemma2:2b
17+
* - library/qwen2.5-coder:0.5b
18+
* - library/qwen2.5-coder:latest
1019
* - library/dolphin3:latest
11-
* - library/llama3:latest
12-
* - library/gemma:2b
13-
* - library/dolphin-llama3:8b
14-
* - library/gemma:latest
15-
* - library/granite3.3:2b
16-
* - library/gemma:latest
17-
* - library/falcon:latest
18-
* - library/tulu3:latest
19-
* - library/dbrx:latest
20-
* - library/smallthinker:latest
21-
* - library/command-r7b:latest
20+
* - library/qwen2:latest
21+
* - library/tinyllama:latest
22+
* - library/gemma3n:latest
23+
* - library/phi4-reasoning:latest
24+
* - library/cogito:latest
25+
* - library/deepseek-coder-v2:latest
26+
* - library/deepscaler:1.5b
27+
* - library/dolphin-phi:2.7b
28+
* - library/llama4:latest
29+
* - library/dolphin-mistral:7b
30+
* - library/devstral:24b
31+
* - library/command-r:latest
32+
* - library/deepcoder:1.5b
33+
* - library/deepcoder:latest
34+
* - library/deepcoder:latest
35+
* - library/vicuna:latest
36+
* - library/codegeex4:latest
37+
* - library/deepseek-v2:16b
38+
* - library/qwen2-math:1.5b
39+
* - library/nous-hermes2:latest
40+
* - library/granite3.1-dense:latest
41+
* - library/command-r-plus:104b
42+
* - library/stablelm2:1.6b
43+
* - library/granite3-dense:latest
44+
* - library/reflection:latest
45+
* - library/exaone3.5:2.4b
46+
* - library/glm4:latest
47+
* - library/llama3-gradient:latest
48+
* - library/athene-v2:72b
49+
* - library/yi-coder:latest
50+
* - library/llama3-groq-tool-use:latest
51+
* - library/nemotron:latest
52+
* - library/reader-lm:latest
53+
* - library/falcon2:latest
54+
* - library/stablelm-zephyr:latest
55+
* - library/command-r7b-arabic:latest
2256
*/
2357

2458
export const OLLAMA_CHAT_TEMPLATE_MAPPING: OllamaChatTemplateMapEntry[] = [
@@ -653,6 +687,23 @@ export const OLLAMA_CHAT_TEMPLATE_MAPPING: OllamaChatTemplateMapEntry[] = [
653687
],
654688
},
655689
},
690+
{
691+
model: "library/granite4:latest",
692+
gguf: "{%- set tools_system_message_prefix = 'You are a helpful assistant with access to the following tools. You may call one or more tools to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>' %}\n{%- set tools_system_message_suffix = '\\n</tools>\\n\\nFor each tool call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call>. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request.' %}\n{%- set documents_system_message_prefix = 'You are a helpful assistant with access to the following documents. You may use one or more documents to assist with the user query.\\n\\nYou are given a list of documents within <documents></documents> XML tags:\\n<documents>' %}\n{%- set documents_system_message_suffix = '\\n</documents>\\n\\nWrite the response to the user\\'s input by strictly aligning with the facts in the provided documents. If the information needed to answer the question is not available in the documents, inform the user that the question cannot be answered based on the available data.' %}\n{%- if available_tools is defined and available_tools %}\n {%- set tools = available_tools %}\n{%- endif %}\n{%- set ns = namespace(tools_system_message=tools_system_message_prefix,\n documents_system_message=documents_system_message_prefix,\n system_message=''\n ) %}\n{%- if tools %}\n {%- for tool in tools %}\n {%- set ns.tools_system_message = ns.tools_system_message + '\\n' + (tool | tojson) %}\n {%- endfor %}\n {%- set ns.tools_system_message = ns.tools_system_message + tools_system_message_suffix %}\n{%- else %}\n {%- set ns.tools_system_message = '' %}\n{%- endif %}\n{%- if documents %}\n {%- for document in documents %}\n {%- set ns.documents_system_message = ns.documents_system_message + '\\n' + (document | tojson) %}\n {%- endfor %}\n {%- set ns.documents_system_message = ns.documents_system_message + documents_system_message_suffix %}\n{%- else %}\n {%- set ns.documents_system_message = '' %}\n{%- endif %}\n{%- if messages[0].role == 'system' %}\n {%- if messages[0].content is string %}\n {%- set ns.system_message = messages[0].content %}\n {%- elif messages[0].content is iterable %}\n {%- for entry in messages[0].content %}\n {%- if entry.type== 'text' %}\n {%- if ns.system_message != '' %}\n {%- set ns.system_message = ns.system_message + '\\n' %}\n {%- endif %}\n {%- set ns.system_message = ns.system_message + entry.text %}\n {%- endif %}\n {%- endfor %}\n {%- endif %}\n {%- if tools and documents %}\n {%- set ns.system_message = ns.system_message + '\\n\\n' + ns.tools_system_message + '\\n\\n' + ns.documents_system_message %}\n {%- elif tools %}\n {%- set ns.system_message = ns.system_message + '\\n\\n' + ns.tools_system_message %}\n {%- elif documents %}\n {%- set ns.system_message = ns.system_message + '\\n\\n' + ns.documents_system_message %}\n {%- endif %}\n{%- else %}\n {%- if tools and documents %}\n {%- set ns.system_message = ns.tools_system_message + '\\n\\n' + ns.documents_system_message %}\n {%- elif tools %}\n {%- set ns.system_message = ns.tools_system_message %}\n {%- elif documents %}\n {%- set ns.system_message = ns.documents_system_message %}\n {%- endif %}\n{%- endif %}\n{%- if ns.system_message %}\n {{- '<|start_of_role|>system<|end_of_role|>' + ns.system_message + '<|end_of_text|>\\n' }}\n{%- endif %}\n{%- for message in messages %}\n {%- set content = namespace(val='') %}\n {%- if message.content is string %}\n {%- set content.val = message.content %}\n {%- else %}\n {%- if message.content is iterable %}\n {%- for entry in message.content %}\n {%- if entry.type== 'text' %}\n {%- if content.val != '' %}\n {%- set content.val = content.val + '\\n' %}\n {%- endif %}\n {%- set content.val = content.val + entry.text %}\n {%- endif %}\n {%- endfor %}\n {%- endif %}\n {%- endif %}\n {%- if (message.role == 'user') or (message.role == 'system' and not loop.first) %}\n {{- '<|start_of_role|>' + message.role + '<|end_of_role|>' + content.val + '<|end_of_text|>\\n' }}\n {%- elif message.role == 'assistant' %}\n {{- '<|start_of_role|>' + message.role + '<|end_of_role|>' + content.val }}\n {%- if message.tool_calls %}\n {%- for tool_call in message.tool_calls %}\n {%- if (loop.first and content.val) or (not loop.first) %}\n {{- '\\n' }}\n {%- endif %}\n {%- if tool_call.function %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {%- if tool_call.arguments is string %}\n {{- tool_call.arguments }}\n {%- else %}\n {{- tool_call.arguments | tojson }}\n {%- endif %}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|end_of_text|>\\n' }}\n {%- elif message.role == 'tool' %}\n {%- if loop.first or (messages[loop.index0 - 1].role != 'tool') %}\n {{- '<|start_of_role|>user<|end_of_role|>' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- content.val }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != 'tool') %}\n {{- '<|end_of_text|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|start_of_role|>assistant<|end_of_role|>' }}\n{%- endif %}",
693+
ollama: {
694+
template:
695+
'{{- /*\n\n------ MESSAGE PARSING ------\n\n*/}}\n{{- /*\nDeclare the system prompt chunks used for different features\n*/}}\n{{- $tools_system_message_prefix := "You are a helpful assistant with access to the following tools. You may call one or more tools to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>" }}\n{{- $tools_system_message_suffix := "\\n</tools>\\n\\nFor each tool call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\"name\\": <function-name>, \\"arguments\\": <args-json-object>}\\n</tool_call>. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request." }}\n{{- $documents_system_message_prefix := "You are a helpful assistant with access to the following documents. You may use one or more documents to assist with the user query.\\n\\nYou are given a list of documents within <documents></documents> XML tags:\\n<documents>" }}\n{{- $documents_system_message_suffix := "\\n</documents>\\n\\nWrite the response to the user\'s input by strictly aligning with the facts in the provided documents. If the information needed to answer the question is not available in the documents, inform the user that the question cannot be answered based on the available data." }}\n\n{{- /*\nDeclare the prompt structure variables to be filled in from messages\n*/}}\n{{- $tools_system_message := "" }}\n{{- $documents_system_message := "" }}\n{{- $system_message := "" }}\n{{- $document_counter := 0 }}\n{{- $last_query_index := 0 }}\n\n{{- /*\nOutput parsing heuristic\n\nOllama has very specific heuristics for parsing the tags for thinking and tool\ncalling. Rather than contorting the actual message expansion to match the\nexpectations, we explicitly put them here behind an unreachable condition.\n*/}}\n{{- if false }}\n {{- /* tool calls: https://github.com/ollama/ollama/blob/main/tools/template.go#L17 */}}\n {{- if .ToolCalls }}<tool_call>{{- end }}\n{{- end }}\n\n{{- /*\nCreate tools system message chunk\n*/}}\n{{- if .Tools }}\n {{- $tools_system_message = print $tools_system_message_prefix }}\n {{- range $_, $tool_body := .Tools }}\n {{- $tools_system_message = print $tools_system_message "\\n" (json $tool_body) }}\n {{- end }}\n {{- $tools_system_message = print $tools_system_message $tools_system_message_suffix }}\n{{- end }}\n\n\n{{- /*\nLoop over messages to parse variables:\n\n- User provided documents in the "document" role\n- Last user query index\n- Initial system message\n\nNOTE: Since Ollama collates consecutive roles, for documents, we work around\n this by allowing the role to contain a qualifier after the role string. This\n is also then used as the title of the document.\n*/ -}}\n{{- range $index, $_ := .Messages }}\n {{- if (and (eq .Role "system") (eq $index 0)) }}\n {{- if ne $system_message "" }}\n {{- $system_message = print $system_message "\\n" }}\n {{- end }}\n {{- $system_message = print $system_message .Content }}\n {{- else if eq .Role "user" }}\n {{- /*\n NOTE: 31 == len \'<tool_response></tool_response>\'. We only check the\n prefix match since go template doesn\'t support negative indexing.\n */}}\n {{- if or (lt (len .Content) 31) (ne (slice .Content 0 15) "<tool_response>") }}\n {{- $last_query_index = $index }}\n {{- end }}\n {{- else if (and (ge (len .Role) 8) (eq (slice .Role 0 8) "document")) }}\n {{- if (eq $document_counter 0)}}\n {{- $documents_system_message = print $documents_system_message_prefix}}\n {{- end }}\n {{- $identifier := ""}}\n {{- if (ge (len .Role) 9) }}\n {{- $identifier = slice .Role 9}}\n {{- end }}\n {{- if (eq $identifier "") }}\n {{- $identifier := print $document_counter}}\n {{- end }}\n {{- $documents_system_message = print $documents_system_message "\\n{\\"doc_id\\": " $document_counter ", \\"title\\": \\"" $identifier "\\", \\"text\\": \\"" .Content "\\"}"}}\n {{- $document_counter = len (printf "a%*s" $document_counter "")}}\n {{- end }}\n{{- end }}\n{{- if (ne $document_counter 0) }}\n{{- $documents_system_message = print $documents_system_message $documents_system_message_suffix}}\n{{- end }}\n\n{{- /*\nConstruct the full system message\n*/}}\n{{- if ne $tools_system_message "" }}\n {{- if ne $system_message "" }}\n {{- $system_message = print $system_message "\\n\\n" }}\n {{- end }}\n {{- $system_message = print $system_message $tools_system_message }}\n{{- end }}\n{{- if ne $documents_system_message "" }}\n {{- if ne $system_message "" }}\n {{- $system_message = print $system_message "\\n\\n" }}\n {{- end }}\n {{- $system_message = print $system_message $documents_system_message }}\n{{- end }}\n\n{{- /*\n\n------ TEMPLATE EXPANSION ------\n\n*/}}\n{{- if ne $system_message "" -}}\n<|start_of_role|>system<|end_of_role|>{{ $system_message }}<|end_of_text|>{{ "\\n" }}\n{{- end }}\n{{- $prev_role := "" }}\n{{- range $message_index, $_ := .Messages }}\n {{- $next_message_index := len (printf "a%*s" $message_index "") }}\n {{- if or (eq .Role "user") (and (eq .Role "system") (ne $message_index 0)) }}\n {{- "" }}<|start_of_role|>{{- .Role }}<|end_of_role|>{{- .Content }}<|end_of_text|>{{ "\\n" }}\n {{- else if eq .Role "assistant" -}}\n {{- "" }}<|start_of_role|>{{ .Role }}<|end_of_role|>{{ .Content }}\n\n {{- /* Expand tool calls */}}\n {{- $content := .Content }}\n {{- if .ToolCalls }}\n {{- range $tool_idx, $tool_call := .ToolCalls }}\n {{- if or (ne $content "") (ne $tool_idx 0) }}\n {{- "\\n" }}\n {{- end }}\n {{- print "<tool_call>\\n{\\"name\\": \\"" $tool_call.Function.Name "\\", \\"arguments\\": " (json $tool_call.Function.Arguments) "}\\n</tool_call>" }}\n {{- end }}\n {{- end }}\n\n {{- /* End assistant block */}}<|end_of_text|>{{ "\\n" }}\n\n {{- else if eq .Role "tool" }}\n {{- if (ne $prev_role "tool") -}}\n <|start_of_role>user<|end_of_role|>\n {{- end }}\n {{- "\\n" }}<tool_response>{{ print "\\n" .Content "\\n" }}</tool_response>\n {{- if ne $next_message_index (len $.Messages) }}\n {{- $next_element := index $.Messages $next_message_index }}\n {{- if ne $next_element.Role "tool" -}}\n <|end_of_text|>{{ "\\n" }}\n {{- end }}\n {{- else -}}\n <|end_of_text|>{{ "\\n" }}\n {{- end }}\n {{- end }}\n\n {{- /* If not an assistant message at the end, add generation prompt */}}\n {{- if and (eq $next_message_index (len $.Messages)) (ne .Role "assistant") }}\n {{- "<|start_of_role|>assistant<|end_of_role|>" }}\n {{- end }}\n{{- end }}',
696+
tokens: [
697+
"<tools>",
698+
"<tool_call>",
699+
"<documents>",
700+
"<|start_of_role|>",
701+
"<|end_of_role|>",
702+
"<|end_of_text|>",
703+
"<tool_response>",
704+
],
705+
},
706+
},
656707
{
657708
model: "library/hermes3:70b",
658709
gguf: "{{bos_token}}{% for message in messages %}{% if loop.first and messages[0]['role'] != 'system' %}{{ '<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n' }}{% endif %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}",

0 commit comments

Comments
 (0)