pub struct ChatTemplate { /* private fields */ }Expand description
Compiled Jinja chat template + BOS/EOS strings.
Implementations§
Source§impl ChatTemplate
impl ChatTemplate
Sourcepub fn from_source(src: impl Into<String>) -> Result<Self>
pub fn from_source(src: impl Into<String>) -> Result<Self>
Compile a chat template from a raw Jinja string.
Sourcepub fn with_tokens(self, bos: Option<String>, eos: Option<String>) -> Self
pub fn with_tokens(self, bos: Option<String>, eos: Option<String>) -> Self
Override BOS/EOS strings (passed to the template as bos_token /
eos_token Jinja variables).
Sourcepub fn from_gguf(path: &Path) -> Result<Self>
pub fn from_gguf(path: &Path) -> Result<Self>
Load template + BOS/EOS from a GGUF file. Reads
tokenizer.chat_template first, then tokenizer.ggml.chat_template.
Sourcepub fn from_gguf_file(raw: &GgufFile) -> Result<Self>
pub fn from_gguf_file(raw: &GgufFile) -> Result<Self>
Same as from_gguf, but reuses an already-parsed file.
pub fn source_text(&self) -> &str
pub fn source_kind(&self) -> &ChatTemplateSource
pub fn bos_token(&self) -> Option<&str>
pub fn eos_token(&self) -> Option<&str>
Sourcepub fn render(
&self,
messages: &[ChatMessage],
add_generation_prompt: bool,
) -> Result<String>
pub fn render( &self, messages: &[ChatMessage], add_generation_prompt: bool, ) -> Result<String>
Render the template with the given messages.
The template sees Jinja variables: messages (list of
{role, content} maps), add_generation_prompt (bool), and
bos_token / eos_token strings (empty if unknown).
Auto Trait Implementations§
impl !Freeze for ChatTemplate
impl !RefUnwindSafe for ChatTemplate
impl Send for ChatTemplate
impl Sync for ChatTemplate
impl Unpin for ChatTemplate
impl UnsafeUnpin 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> 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