pub struct Tokenizer;Expand description
Token counting utility using character-based estimation. Uses ~4 characters per token as a reasonable approximation.
Stateless. Only counting is implemented; context-window budget is
enforced via MAX_CONTEXT_TOKENS / CONTEXT_RESERVE_TOKENS
constants and the user’s num_ctx Ollama option. The old
per-model-family table (get_max_tokens / remaining_tokens) and
the base_model_name field were never consulted by the budget
logic and have been deleted.
Implementations§
Source§impl Tokenizer
impl Tokenizer
Sourcepub fn new(_model_name: &str) -> Self
pub fn new(_model_name: &str) -> Self
Create a new tokenizer. The model_name parameter is accepted
for call-site compatibility but ignored — the count is a pure
function of text length.
Sourcepub fn count_tokens(&self, text: &str) -> Result<usize>
pub fn count_tokens(&self, text: &str) -> Result<usize>
Count tokens in a single text string (~4 chars per token)
Auto Trait Implementations§
impl Freeze for Tokenizer
impl RefUnwindSafe for Tokenizer
impl Send for Tokenizer
impl Sync for Tokenizer
impl Unpin for Tokenizer
impl UnsafeUnpin for Tokenizer
impl UnwindSafe for Tokenizer
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