pub struct ChatTemplateState { /* private fields */ }Expand description
Chat template state that can be embedded in any tokenizer struct. Eliminates duplicated apply/set/format methods across tokenizer backends.
The compiled minijinja::Environment (with the template parsed, filters
registered, and Python-compat callback installed) is cached so that
apply() only performs rendering – no parsing or environment setup.
The cache is rebuilt whenever set() is called.
Environment<'static> is both Send and Sync, so embedding this in
tokenizer structs shared across threads is safe.
Implementations§
Source§impl ChatTemplateState
impl ChatTemplateState
pub fn new(template: Option<String>) -> Result<Self>
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Create a ChatTemplateState with no template set.
Unlike new(None), this is infallible since there is no template to
parse — useful in constructors that don’t return Result.
pub fn apply( &self, messages: &[Value], params: ChatTemplateParams<'_>, ) -> Result<String>
pub fn set(&mut self, template: String) -> Result<()>
pub fn content_format(&self) -> ChatTemplateContentFormat
pub fn thinking_toggle(&self) -> ThinkingToggle
pub fn thinking_key_name(&self) -> Option<ThinkingKeyName>
pub fn think_in_prefill(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ChatTemplateState
impl !RefUnwindSafe for ChatTemplateState
impl Send for ChatTemplateState
impl Sync for ChatTemplateState
impl Unpin for ChatTemplateState
impl UnsafeUnpin for ChatTemplateState
impl !UnwindSafe for ChatTemplateState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more