pub struct TokenizerSpec {
pub tokenizer_json: PathBuf,
pub added_tokens: HashMap<u32, String>,
pub chat_template: Option<String>,
}Expand description
Where to find the tokenizer and which special tokens it defines.
Fields§
§tokenizer_json: PathBufPath to the HuggingFace tokenizer.json.
added_tokens: HashMap<u32, String>Added special tokens parsed from tokenizer_config.json
(added_tokens_decoder): token id → token string (e.g. <|im_end|>).
chat_template: Option<String>Raw chat template string (Jinja) if present in tokenizer_config.json.
Phase 1 uses a built-in ChatML wrap instead of evaluating Jinja.
Implementations§
Source§impl TokenizerSpec
impl TokenizerSpec
Sourcepub fn special_token_id(&self, token: &str) -> Option<u32>
pub fn special_token_id(&self, token: &str) -> Option<u32>
Looks up the id of an added special token by its string, e.g.
spec.special_token_id("<|im_end|>").
Sourcepub fn chatml_wrap(&self, user_prompt: &str) -> Option<String>
pub fn chatml_wrap(&self, user_prompt: &str) -> Option<String>
Wraps a user prompt in the ChatML template used by SmolLM2-style
instruction models. Returns None if the tokenizer does not define
<|im_start|> / <|im_end|> tokens.
Trait Implementations§
Source§impl Clone for TokenizerSpec
impl Clone for TokenizerSpec
Source§fn clone(&self) -> TokenizerSpec
fn clone(&self) -> TokenizerSpec
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for TokenizerSpec
impl RefUnwindSafe for TokenizerSpec
impl Send for TokenizerSpec
impl Sync for TokenizerSpec
impl Unpin for TokenizerSpec
impl UnsafeUnpin for TokenizerSpec
impl UnwindSafe for TokenizerSpec
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