pub struct ChatTemplateProcessor { /* private fields */ }Expand description
Chat template processor using Jinja2 - simple wrapper like HuggingFace
Implementations§
Source§impl ChatTemplateProcessor
impl ChatTemplateProcessor
Sourcepub fn new(template: String) -> Result<Self>
pub fn new(template: String) -> Result<Self>
Create a new chat template processor.
Returns an error if the template fails to parse, so callers get an actionable message immediately rather than a confusing “template not found” error on the first render.
Sourcepub fn apply_chat_template(
&self,
messages: &[Value],
params: ChatTemplateParams<'_>,
) -> Result<String>
pub fn apply_chat_template( &self, messages: &[Value], params: ChatTemplateParams<'_>, ) -> Result<String>
Apply the chat template to a list of messages
This mimics the behavior of HuggingFace’s apply_chat_template method but returns the formatted string instead of token IDs. Messages should be pre-processed into the format expected by the template.
Auto Trait Implementations§
impl !Freeze for ChatTemplateProcessor
impl !RefUnwindSafe for ChatTemplateProcessor
impl Send for ChatTemplateProcessor
impl Sync for ChatTemplateProcessor
impl Unpin for ChatTemplateProcessor
impl UnsafeUnpin for ChatTemplateProcessor
impl !UnwindSafe for ChatTemplateProcessor
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