pub trait Tokenizer {
// Required methods
fn apply_chat_template(
&self,
messages: &[Message],
chat_template: &str,
tokenize: bool,
add_generation_prompt: bool,
enable_thinking: bool,
) -> String;
fn encode(&self, texts: &[String]) -> Vec<usize>;
fn decode(&self, ids: &[usize]) -> String;
}Expand description
Text tokenization and chat-templating, implemented per model/tokenizer family.
Required Methods§
Sourcefn apply_chat_template(
&self,
messages: &[Message],
chat_template: &str,
tokenize: bool,
add_generation_prompt: bool,
enable_thinking: bool,
) -> String
fn apply_chat_template( &self, messages: &[Message], chat_template: &str, tokenize: bool, add_generation_prompt: bool, enable_thinking: bool, ) -> String
Renders messages through chat_template (a Jinja-style template string, per the Hugging
Face chat-template convention), optionally tokenizing the result (tokenize), appending a
generation prompt (add_generation_prompt), and enabling “thinking”/reasoning mode
(enable_thinking) for models that support it.