[GH-ISSUE #7348] RFC: multi-template models #4669

Closed
opened 2026-04-12 15:35:22 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @rick-github on GitHub (Oct 24, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/7348

Some models are being released with multiple chat_templates, eg Aya-Expanse 32B & 8B which has a default template but also templates tuned for RAG and Tool use.

There's a few ways these could be supported.

  1. Mash all of the templates together and add a new option to the API request that the golang template can access.
{{- if eq .TemplateSelector "rag" }}{{ system_message = 'Decide which of the retrieved documents are relevant to the user" }}
{{- else if eq .TemplateSelector "tool_use" }}{{ system_message = "You can use the following tools" }}
{{- else system_message =  "You are Aya, a brilliant, sophisticated, multilingual AI-assistant" }}
{{- end }}
<BOS_TOKEN>
...
  1. Give the API the ability to supply a template. This currently works for /api/generate but not /api/chat, and requires some surgery to make it work.
  2. Create different versions of the model with the same GGUF with different TEMPLATE statements. This is easiest but requires loading the same model multiple times.
  3. Modifying TEMPLATE processing to support TEMPLATE[]. Also requires metadata in the API call to choose the appropriate template.

Is there any appetite for supporting multi-template models?

Originally created by @rick-github on GitHub (Oct 24, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/7348 Some models are being released with multiple chat_templates, eg [Aya-Expanse 32B & 8B](https://huggingface.co/CohereForAI/aya-expanse-8b/blob/b9848575c8731981dfcf2e1f3bfbcb917a2e585d/tokenizer_config.json#L304) which has a default template but also templates tuned for RAG and Tool use. There's a few ways these could be supported. 1. Mash all of the templates together and add a new option to the API request that the golang template can access. ```go {{- if eq .TemplateSelector "rag" }}{{ system_message = 'Decide which of the retrieved documents are relevant to the user" }} {{- else if eq .TemplateSelector "tool_use" }}{{ system_message = "You can use the following tools" }} {{- else system_message = "You are Aya, a brilliant, sophisticated, multilingual AI-assistant" }} {{- end }} <BOS_TOKEN> ... ``` 2. Give the API the ability to supply a template. This currently works for `/api/generate` but not `/api/chat`, and requires some surgery to make it work. 3. Create different versions of the model with the same GGUF with different TEMPLATE statements. This is easiest but requires loading the same model multiple times. 4. Modifying TEMPLATE processing to support TEMPLATE[]. Also requires metadata in the API call to choose the appropriate template. Is there any appetite for supporting multi-template models?
GiteaMirror added the feature request label 2026-04-12 15:35:22 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#4669