pub struct ChatTemplate { /* private fields */ }Expand description
Chat template renderer using MiniJinja
Implementations§
Source§impl ChatTemplate
impl ChatTemplate
Sourcepub fn new(
template: impl Into<String>,
bos_token: impl Into<String>,
eos_token: impl Into<String>,
) -> Result<Self, ChatTemplateError>
pub fn new( template: impl Into<String>, bos_token: impl Into<String>, eos_token: impl Into<String>, ) -> Result<Self, ChatTemplateError>
Create from a Jinja template string
Sourcepub fn from_tokenizer_config(
path: impl AsRef<Path>,
) -> Result<Self, ChatTemplateError>
pub fn from_tokenizer_config( path: impl AsRef<Path>, ) -> Result<Self, ChatTemplateError>
Load chat template from a tokenizer_config.json file
Sourcepub fn from_tokenizer_config_str(json: &str) -> Result<Self, ChatTemplateError>
pub fn from_tokenizer_config_str(json: &str) -> Result<Self, ChatTemplateError>
Load chat template from tokenizer_config.json content
Sourcepub fn chatml_with_thinking() -> Self
pub fn chatml_with_thinking() -> Self
ChatML template with thinking/reasoning support
Sourcepub fn apply(
&self,
messages: &[Message],
options: &ChatTemplateOptions,
) -> Result<String, ChatTemplateError>
pub fn apply( &self, messages: &[Message], options: &ChatTemplateOptions, ) -> Result<String, ChatTemplateError>
Apply the chat template to messages
Sourcepub fn apply_for_generation(
&self,
messages: &[Message],
) -> Result<String, ChatTemplateError>
pub fn apply_for_generation( &self, messages: &[Message], ) -> Result<String, ChatTemplateError>
Convenience method: apply with add_generation_prompt=true
Auto Trait Implementations§
impl !Freeze for ChatTemplate
impl !RefUnwindSafe for ChatTemplate
impl Send for ChatTemplate
impl Sync for ChatTemplate
impl Unpin for ChatTemplate
impl !UnwindSafe for ChatTemplate
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