pub struct TokenEstimator { /* private fields */ }Expand description
Token estimator for mixed-language text
Implementations§
Source§impl TokenEstimator
impl TokenEstimator
Sourcepub const fn new(cjk_factor: f32, latin_factor: f32) -> Self
pub const fn new(cjk_factor: f32, latin_factor: f32) -> Self
Create a new token estimator with custom factors
§Example
use llm_token::estimation::TokenEstimator;
let estimator = TokenEstimator::new(0.8, 0.3);Sourcepub fn estimate(text: &str) -> usize
pub fn estimate(text: &str) -> usize
Estimate token count for text using default factors
§Example
use llm_token::estimation::TokenEstimator;
let tokens = TokenEstimator::estimate("Hello world");Sourcepub fn estimate_with_config(&self, text: &str) -> usize
pub fn estimate_with_config(&self, text: &str) -> usize
Estimate token count for text with this estimator’s configuration
Uses fast path for ASCII-only text, otherwise processes character by character.
Sourcepub fn estimate_text(&self, text: &str) -> usize
pub fn estimate_text(&self, text: &str) -> usize
Estimate tokens for text (instance method)
Convenience method that delegates to estimate_with_config.
Sourcepub fn find_split_point(&self, text: &str, max_tokens: usize) -> usize
pub fn find_split_point(&self, text: &str, max_tokens: usize) -> usize
Find split point that fits within token limit
Returns the byte offset where to split.
Trait Implementations§
Source§impl Clone for TokenEstimator
impl Clone for TokenEstimator
impl Copy for TokenEstimator
Source§impl Debug for TokenEstimator
impl Debug for TokenEstimator
Auto Trait Implementations§
impl Freeze for TokenEstimator
impl RefUnwindSafe for TokenEstimator
impl Send for TokenEstimator
impl Sync for TokenEstimator
impl Unpin for TokenEstimator
impl UnsafeUnpin 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