Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Ollama Ollama Template Index

From Leeroopedia
Knowledge Sources
Domains Chat Template, Model Configuration
Last Updated 2025-02-15 00:00 GMT

Overview

JSON index file that maps HuggingFace chat template strings to their corresponding Ollama template names, enabling automatic template detection during model import.

Description

Contains an array of objects, each with a template field (the raw Jinja2 chat template string from HuggingFace tokenizer_config.json) and a name field (the Ollama template name). Covers major template families including chatml, llama2-chat, llama3-instruct, mistral-instruct, gemma-instruct, gemma3-instruct, phi-3, zephyr, command-r, openchat, alpaca, chatqa, granite-instruct, falcon-instruct, solar-instruct, magicoder, starcoder2-instruct, alfred, and codellama-70b-instruct. Multiple HuggingFace template variants can map to the same Ollama template name.

Usage

Used during model import to detect which Ollama Go template to use based on the HuggingFace chat template string found in the model's tokenizer configuration.

Code Reference

Source Location

  • Repository: Ollama
  • File: template/index.json
  • Lines: 1-150

Signature

[
  {
    "template": "{% for message in messages %}{{'<|im_start|>' + ...}}{% endfor %}",
    "name": "chatml"
  },
  {
    "template": "{{ bos_token }}{% for message in messages %}...",
    "name": "llama3-instruct"
  }
]

Import

// Loaded as embedded resource via Go embed
//go:embed index.json
var indexJSON []byte

I/O Contract

Inputs

Name Type Required Description
(file read) JSON Yes Parsed as array of {template, name} objects

Outputs

Name Type Description
entries []TemplateEntry Array of template-to-name mappings

Usage Examples

// Example entry mapping a chatml variant
{
  "template": "{% for message in messages %}{{'<|im_start|>' + message['role'] + '\\n' + message['content'] + '<|im_end|>' + '\\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\\n' }}{% endif %}",
  "name": "chatml"
}

// Example entry for llama3
{
  "template": "{% set loop_messages = messages %}{% for message in loop_messages %}{% set content = '<|start_header_id|>' + message['role'] + '<|end_header_id|>\\n\\n'+ message['content'] | trim + '<|eot_id|>' %}...",
  "name": "llama3-instruct"
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment