pub enum ChatTemplate {
UserAssistant,
ChatML,
Llama2,
None,
}Expand description
Detected chat template format from the GGUF metadata.
Variants§
UserAssistant
<|user|>\n...<|assistant|>\n format
ChatML
ChatML: <|im_start|>user\n...<|im_end|>\n<|im_start|>assistant\n
Llama2
Llama-2: [INST] ... [/INST]
None
No template detected, use raw text.
Implementations§
Source§impl ChatTemplate
impl ChatTemplate
Sourcepub fn from_tokenizer_config(path: &Path) -> Option<Self>
pub fn from_tokenizer_config(path: &Path) -> Option<Self>
Detect chat template from a HuggingFace tokenizer_config.json file.
Reads the chat_template field (a Jinja2 string) and pattern-matches
against known token markers. Returns None on any IO or parse error.
Sourcepub fn detect_from_model_type(model_type: Option<&str>) -> Self
pub fn detect_from_model_type(model_type: Option<&str>) -> Self
Detect chat template from model type string (for ONNX models without GGUF metadata).
Sourcepub fn wrap_prompt(&self, prompt: &str) -> String
pub fn wrap_prompt(&self, prompt: &str) -> String
Wrap a raw prompt in the appropriate chat format.
Sourcepub fn format_first_turn(
&self,
system_prompt: &str,
user_message: &str,
) -> String
pub fn format_first_turn( &self, system_prompt: &str, user_message: &str, ) -> String
Format a chat message with system prompt for the first turn.
Sourcepub fn format_continuation(&self, user_message: &str) -> String
pub fn format_continuation(&self, user_message: &str) -> String
Format a continuation turn (not the first message).
Sourcepub fn stop_patterns(&self) -> &[&str]
pub fn stop_patterns(&self) -> &[&str]
Patterns that indicate the model is trying to generate a new user turn (i.e., the response is complete).
Trait Implementations§
Source§impl Clone for ChatTemplate
impl Clone for ChatTemplate
Source§fn clone(&self) -> ChatTemplate
fn clone(&self) -> ChatTemplate
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ChatTemplate
impl Debug for ChatTemplate
Source§impl PartialEq for ChatTemplate
impl PartialEq for ChatTemplate
Source§fn eq(&self, other: &ChatTemplate) -> bool
fn eq(&self, other: &ChatTemplate) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for ChatTemplate
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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>
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>
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