pub struct ChatTemplate {
pub bos_token: Option<BeginEndUnkTok>,
pub eos_token: Option<BeginEndUnkTok>,
pub unk_token: Option<BeginEndUnkTok>,
pub chat_template: Option<ChatTemplateValue>,
/* private fields */
}Expand description
Template for chat models including bos/eos/unk as well as the chat template.
Fields§
§bos_token: Option<BeginEndUnkTok>§eos_token: Option<BeginEndUnkTok>§unk_token: Option<BeginEndUnkTok>§chat_template: Option<ChatTemplateValue>Jinja format chat templating for chat completion.
Implementations§
Source§impl ChatTemplate
impl ChatTemplate
pub fn eos_tok(&self) -> Option<String>
pub fn bos_tok(&self) -> Option<String>
pub fn unk_tok(&self) -> Option<String>
Sourcepub fn with_tokenizer_json(self, tokenizer_json: &str) -> Result<Self>
pub fn with_tokenizer_json(self, tokenizer_json: &str) -> Result<Self>
Add the added_tokens of the model’s tokenizer.json to
ChatTemplate::added_token_spellings. Some repos declare no
added_tokens_decoder in tokenizer_config.json (DeepSeek V3/R1,
GLM-5, Gemma 4), so their chat markers are listed only there.
Sourcepub fn with_request_control_tokens_as_text(self, enabled: bool) -> Self
pub fn with_request_control_tokens_as_text(self, enabled: bool) -> Self
Whether control-token spellings in request text render as ordinary
text, so that only the template’s own markers encode as control tokens.
On by default; false turns it off, except under a template with
Harmony framing, which always renders this way.
The spellings come back as ordinary segments of
OAIPromptFormatter::render_prompt,
to encode with crate::RenderedPrompt::encode_segments; render
returns the same text without them. A model that lists its markers
only in tokenizer.json also needs ChatTemplate::with_tokenizer_json.
In assistant history, a marker the template itself reads stays a
control token.
Trait Implementations§
Source§impl Debug for ChatTemplate
impl Debug for ChatTemplate
Source§impl Default for ChatTemplate
impl Default for ChatTemplate
Source§impl<'de> Deserialize<'de> for ChatTemplate
impl<'de> Deserialize<'de> for ChatTemplate
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Forget for ChatTemplate
impl Freeze for ChatTemplate
impl Move 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
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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