Skip to content

Commit f184b8d

Browse files
[ollama-utils] 🤖 Auto-update chat templates (2025-09-01) (#1714)
This PR is auto-generated by [generate-automap.ts](https://github.com/huggingface/huggingface.js/blob/main/packages/ollama-utils/scripts/generate-automap.ts). Co-authored-by: machineuser <[email protected]>
1 parent 5ff0978 commit f184b8d

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

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

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

66
/**
77
* Skipped these models due to error:
8-
* - library/llama3.2:latest
9-
* - library/llama2:latest
10-
* - library/llama3.1:latest
11-
* - library/deepseek-v3:latest
12-
* - library/cogito:3b
13-
* - library/phi4-mini:latest
14-
* - library/qwen3-coder:latest
15-
* - library/granite3.2-vision:latest
16-
* - library/opencoder:latest
17-
* - library/opencoder:1.5b
18-
* - library/phind-codellama:latest
19-
* - library/yarn-mistral:latest
20-
* - library/stablelm-zephyr:latest
8+
* - library/llama3.3:latest
9+
* - library/llama3.2-vision:latest
10+
* - 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
2122
*/
2223

2324
export const OLLAMA_CHAT_TEMPLATE_MAPPING: OllamaChatTemplateMapEntry[] = [
@@ -364,6 +365,31 @@ export const OLLAMA_CHAT_TEMPLATE_MAPPING: OllamaChatTemplateMapEntry[] = [
364365
},
365366
},
366367
},
368+
{
369+
model: "library/deepseek-v3.1:latest",
370+
gguf: "{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% if not thinking is defined %}{% set thinking = false %}{% endif %}{% set ns = namespace(is_first=false, is_tool=false, system_prompt='', is_first_sp=true, is_last_user=false) %}{%- for message in messages %}{%- if message['role'] == 'system' %}{%- if ns.is_first_sp %}{% set ns.system_prompt = ns.system_prompt + message['content'] %}{% set ns.is_first_sp = false %}{%- else %}{% set ns.system_prompt = ns.system_prompt + '\n\n' + message['content'] %}{%- endif %}{%- endif %}{%- endfor %}{{ bos_token }}{{ ns.system_prompt }}{%- for message in messages %}{%- if message['role'] == 'user' %}{%- set ns.is_tool = false -%}{%- set ns.is_first = false -%}{%- set ns.is_last_user = true -%}{{'<|User|>' + message['content']}}{%- endif %}{%- if message['role'] == 'assistant' and message['tool_calls'] is defined and message['tool_calls'] is not none %}{%- if ns.is_last_user %}{{'<|Assistant|></think>'}}{%- endif %}{%- set ns.is_last_user = false -%}{%- set ns.is_first = false %}{%- set ns.is_tool = false -%}{%- for tool in message['tool_calls'] %}{%- if not ns.is_first %}{%- if message['content'] is none %}{{'<|tool▁calls▁begin|><|tool▁call▁begin|>'+ tool['function']['name'] + '<|tool▁sep|>' + tool['function']['arguments'] + '<|tool▁call▁end|>'}}{%- else %}{{message['content'] + '<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['function']['name'] + '<|tool▁sep|>' + tool['function']['arguments'] + '<|tool▁call▁end|>'}}{%- endif %}{%- set ns.is_first = true -%}{%- else %}{{'<|tool▁call▁begin|>'+ tool['function']['name'] + '<|tool▁sep|>' + tool['function']['arguments'] + '<|tool▁call▁end|>'}}{%- endif %}{%- endfor %}{{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}{%- endif %}{%- if message['role'] == 'assistant' and (message['tool_calls'] is not defined or message['tool_calls'] is none) %}{%- if ns.is_last_user %}{{'<|Assistant|>'}}{%- if message['prefix'] is defined and message['prefix'] and thinking %}{{'<think>'}} {%- else %}{{'</think>'}}{%- endif %}{%- endif %}{%- set ns.is_last_user = false -%}{%- if ns.is_tool %}{{message['content'] + '<|end▁of▁sentence|>'}}{%- set ns.is_tool = false -%}{%- else %}{%- set content = message['content'] -%}{%- if '</think>' in content %}{%- set content = content.split('</think>', 1)[1] -%}{%- endif %}{{content + '<|end▁of▁sentence|>'}}{%- endif %}{%- endif %}{%- if message['role'] == 'tool' %}{%- set ns.is_last_user = false -%}{%- set ns.is_tool = true -%}{{'<|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}{%- endif %}{%- endfor -%}{%- if add_generation_prompt and ns.is_last_user and not ns.is_tool %}{{'<|Assistant|>'}}{%- if not thinking %}{{'</think>'}}{%- else %}{{'<think>'}}{%- endif %}{% endif %}",
371+
ollama: {
372+
template:
373+
'{{ .System }}\n{{- if .Tools }}{{ if .System }}\n\n{{ end }}## Tools\nYou have access to the following tools:\n\n{{- range .Tools }}\n\n### {{ .Function.Name }}\nDescription: {{ .Function.Description }}\n\nParameters: {{ .Function.Parameters }}\n{{- end }}\n\nIMPORTANT: ALWAYS adhere to this exact format for tool use:\n<|tool▁calls▁begin|><|tool▁call▁begin|>tool_call_name<|tool▁sep|>tool_call_arguments<|tool▁call▁end|>{{ `{{additional_tool_calls}}` }}<|tool▁calls▁end|>\n\nWhere:\n- `tool_call_name` must be an exact match to one of the available tools\n- `tool_call_arguments` must be valid JSON that strictly follows the tool\'s Parameters Schema\n- For multiple tool calls, chain them directly without separators or spaces\n{{- end }}\n{{- range $i, $_ := .Messages }}\n{{- $last := eq (len (slice $.Messages $i)) 1}}\n{{- if eq .Role "user" }}<|User|>{{ .Content }}\n{{- else if eq .Role "tool" }}<|tool▁output▁begin|>{{ .Content }}<|tool▁output▁end|>\n{{- else if eq .Role "assistant" }}<|Assistant|>\n{{- if and $.IsThinkSet (and $last .Thinking) -}}\n<think>\n{{ .Thinking }}\n</think>\n{{- end }}\n{{- if .ToolCalls }}<|tool▁calls▁begin|>\n{{- range .ToolCalls }}<|tool▁call▁begin|>{{ .Function.Name }}<|tool▁sep|>{{ .Function.Arguments }}<|tool▁call▁end|>{{ end }}<|tool▁calls▁end|>\n{{- else if .Content }}{{ .Content }}{{- end }}\n{{- if not $last }}<|end▁of▁sentence|>{{ end }}\n{{- end }}\n{{- if and $last (ne .Role "assistant") }}<|Assistant|>\n{{- if and $.IsThinkSet $.Think (not $.Tools) -}}\n<think>\n{{- else -}}\n</think>\n{{- end }}\n{{- end }}\n{{- end }}',
374+
tokens: [
375+
"<|User|>",
376+
"<|Assistant|>",
377+
"<|tool▁calls▁begin|>",
378+
"<|tool▁call▁begin|>",
379+
"<|tool▁sep|>",
380+
"<|tool▁call▁end|>",
381+
"<|tool▁calls▁end|>",
382+
"<|end▁of▁sentence|>",
383+
"<think>",
384+
"<|tool▁output▁begin|>",
385+
"<|tool▁output▁end|>",
386+
],
387+
params: {
388+
temperature: 0.6,
389+
top_p: 0.95,
390+
},
391+
},
392+
},
367393
{
368394
model: "library/devstral:latest",
369395
gguf: "{%- set today = strftime_now(\"%Y-%m-%d\") %}\n{%- set default_system_message = \"You are Devstral, a Large Language Model (LLM) created by Mistral AI, a French startup headquartered in Paris.\\nYour knowledge base was last updated on 2023-10-01. The current date is \" + today + \".\\n\\nWhen you're not sure about some information, you say that you don't have the information and don't make up anything.\\nIf the user's question is not clear, ambiguous, or does not provide enough context for you to accurately answer the question, you do not try to answer it right away and you rather ask the user to clarify their request (e.g. \\\"What are some good restaurants around me?\\\" => \\\"Where are you?\\\" or \\\"When is the next flight to Tokyo\\\" => \\\"Where do you travel from?\\\")\" %}\n\n{{- bos_token }}\n\n{%- if messages[0]['role'] == 'system' %}\n {%- set system_message = messages[0]['content'] %}\n {%- set loop_messages = messages[1:] %}\n{%- else %}\n {%- set system_message = default_system_message %}\n {%- set loop_messages = messages %}\n{%- endif %}\n{{- '[SYSTEM_PROMPT]' + system_message + '[/SYSTEM_PROMPT]' }}\n\n{%- for message in loop_messages %}\n {%- if message['role'] == 'user' %}\n {{- '[INST]' + message['content'] + '[/INST]' }}\n {%- elif message['role'] == 'system' %}\n {{- '[SYSTEM_PROMPT]' + message['content'] + '[/SYSTEM_PROMPT]' }}\n {%- elif message['role'] == 'assistant' %}\n {{- message['content'] + eos_token }}\n {%- else %}\n {{- raise_exception('Only user, system and assistant roles are supported!') }}\n {%- endif %}\n{%- endfor %}",

0 commit comments

Comments
 (0)