Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/ollama-utils/src/chat-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ const CUSTOM_TEMPLATE_MAPPING: ((ggufTmpl: string) => OllamaCustomMappedTemplate
stop: "[INST]",
}
: undefined,
(ggufTmpl: string) =>
ggufTmpl.match(/rwkv-world/)
? {
// ref: https://huggingface.co/BlinkDL/rwkv-5-world
ollamaTmpl: "{{ .System }}\nUser: {{ .Prompt }}\n\nAssistant:",
stop: "### Instruction:",
}
: undefined,
(ggufTmpl: string) =>
(ggufTmpl.match(/\[gMASK\]<sop>/) && ggufTmpl.match(/<\|user\|>/)) || ggufTmpl.match(/chatglm4/)
? {
// ref: https://huggingface.co/THUDM/GLM-4-9B-0414
ollamaTmpl:
"[gMASK]<sop>{{ if .System }}<|system|>\n{{ .System }}{{ end }}{{ if .Prompt }}<|user|>\n{{ .Prompt }}{{ end }}<|assistant|>\n{{ .Response }}",
stop: "<|user|>",
}
: undefined,
];

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