Skip to main content

Module chat_template

Module chat_template 

Source
Expand description

Chat template support for tokenizers using Jinja2 templates

This module provides functionality to apply chat templates to messages, similar to HuggingFace transformers’ apply_chat_template method.

Structs§

ChatTemplateParams
Parameters for chat template application
ChatTemplateProcessor
Chat template processor using Jinja2 - simple wrapper like HuggingFace
ChatTemplateState
Chat template state that can be embedded in any tokenizer struct. Eliminates duplicated apply/set/format methods across tokenizer backends.

Enums§

ChatTemplateContentFormat
Chat template content format
ThinkingKeyName
Result of detecting the thinking/reasoning toggle in a chat template. The variable name the template uses for the thinking toggle.
ThinkingToggle

Functions§

detect_chat_template_content_format
Detect the content format expected by a Jinja2 chat template
detect_thinking_toggle
Detect whether the chat template supports a thinking/reasoning toggle and what its default value is.
load_chat_template_from_config
Load chat template from tokenizer config JSON
load_chat_template_from_file
Load chat template from a file (.jinja or .json containing Jinja). Shared between all tokenizer backends.