Skip to content

Commit fb7a075

Browse files
authored
ollama: add custom mapping for glm4 and rwkv (#1403)
Add custom mapping to support RWKV and some edge cases with GLM4 model
1 parent a1befa1 commit fb7a075

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,23 @@ const CUSTOM_TEMPLATE_MAPPING: ((ggufTmpl: string) => OllamaCustomMappedTemplate
9191
stop: "[INST]",
9292
}
9393
: undefined,
94+
(ggufTmpl: string) =>
95+
ggufTmpl.match(/rwkv-world/)
96+
? {
97+
// ref: https://huggingface.co/BlinkDL/rwkv-5-world
98+
ollamaTmpl: "{{ .System }}\nUser: {{ .Prompt }}\n\nAssistant:",
99+
stop: "### Instruction:",
100+
}
101+
: undefined,
102+
(ggufTmpl: string) =>
103+
(ggufTmpl.match(/\[gMASK\]<sop>/) && ggufTmpl.match(/<\|user\|>/)) || ggufTmpl.match(/chatglm4/)
104+
? {
105+
// ref: https://huggingface.co/THUDM/GLM-4-9B-0414
106+
ollamaTmpl:
107+
"[gMASK]<sop>{{ if .System }}<|system|>\n{{ .System }}{{ end }}{{ if .Prompt }}<|user|>\n{{ .Prompt }}{{ end }}<|assistant|>\n{{ .Response }}",
108+
stop: "<|user|>",
109+
}
110+
: undefined,
94111
];
95112

96113
export function convertGGUFTemplateToOllama(
@@ -104,6 +121,9 @@ export function convertGGUFTemplateToOllama(
104121
if (!gguf.chat_template) {
105122
return undefined;
106123
}
124+
if (gguf.chat_template.match(/outetts-\d/)) {
125+
throw new Error("OuteTTS is not a text model");
126+
}
107127
// try matching by first 128 characters (allowing a bit of flexibility)
108128
const truncatedGGUFTmpl = gguf.chat_template.substring(0, 128);
109129
for (const tmpl of OLLAMA_CHAT_TEMPLATE_MAPPING) {

0 commit comments

Comments
 (0)