pub struct ChatTemplateBuilder { /* private fields */ }Expand description
Builder for ChatTemplate, exposing the knobs that affect rendering semantics.
Defaults mirror the transformers reference environment:
trim_blocks = true, lstrip_blocks = true, keep_trailing_newline = true,
lenient undefined behavior, pycompat enabled, SystemClock.
Implementations§
Source§impl ChatTemplateBuilder
impl ChatTemplateBuilder
Sourcepub fn special_tokens_from(self, config: &TokenizerConfig) -> Self
pub fn special_tokens_from(self, config: &TokenizerConfig) -> Self
Inject special tokens (bos_token, …) from a parsed tokenizer_config.json into the
render context, replacing any already set. Use with ChatTemplate::builder when the
template source is a standalone chat_template.jinja but the tokens still live in the
config (see ChatTemplate::from_template_and_config).
Sourcepub fn template_name(self, name: impl Into<String>) -> Self
pub fn template_name(self, name: impl Into<String>) -> Self
Select a named sub-template (e.g. "tool_use", "rag") when the config carries a
list of them. Ignored for a single-string source.
Sourcepub fn clock(self, clock: impl Clock + 'static) -> Self
pub fn clock(self, clock: impl Clock + 'static) -> Self
Inject a deterministic Clock for strftime_now (essential for golden tests).
Sourcepub fn pycompat(self, enabled: bool) -> Self
pub fn pycompat(self, enabled: bool) -> Self
Enable/disable the pycompat Python-method shim. Default: enabled.
Sourcepub fn undefined_behavior(self, ub: UndefinedBehavior) -> Self
pub fn undefined_behavior(self, ub: UndefinedBehavior) -> Self
Override how undefined variables are treated. Default: UndefinedBehavior::Lenient.
Sourcepub fn build(self) -> Result<ChatTemplate, Error>
pub fn build(self) -> Result<ChatTemplate, Error>
Compile the template. Returns Error::Compile on a Jinja syntax error, or
Error::Config if a requested/needed named template can’t be resolved.