pub struct TokenEstimator;
Expand description
Import token estimation from ck-embed Simple token estimation for code and text This is a rough approximation since we don’t have access to the actual model tokenizer
Implementations§
Source§impl TokenEstimator
impl TokenEstimator
Sourcepub fn estimate_tokens(text: &str) -> usize
pub fn estimate_tokens(text: &str) -> usize
Estimate token count for text Based on empirical analysis of code and text tokenization:
- Code: ~4.2 characters per token
- Text: ~4.8 characters per token
- Average: ~4.5 characters per token
Sourcepub fn exceeds_limit(text: &str, max_tokens: usize) -> bool
pub fn exceeds_limit(text: &str, max_tokens: usize) -> bool
Check if text exceeds token limit for a given model
Sourcepub fn get_model_limit(model_name: &str) -> usize
pub fn get_model_limit(model_name: &str) -> usize
Get token limit for different models
Auto Trait Implementations§
impl Freeze for TokenEstimator
impl RefUnwindSafe for TokenEstimator
impl Send for TokenEstimator
impl Sync for TokenEstimator
impl Unpin for TokenEstimator
impl UnwindSafe for TokenEstimator
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