pub struct TokenEstimator { /* private fields */ }Expand description
Token estimator
Implementations§
Source§impl TokenEstimator
impl TokenEstimator
Sourcepub fn with_config(config: TokenEstimatorConfig) -> Self
pub fn with_config(config: TokenEstimatorConfig) -> Self
Create with custom config
Sourcepub fn estimate_value(&self, value: &SochValue) -> usize
pub fn estimate_value(&self, value: &SochValue) -> usize
Estimate tokens for a single value.
Applies safety_margin to the raw estimate to reduce the risk
of exceeding the LLM context window with non-Latin or structured text.
Sourcepub fn estimate_row(&self, values: &[SochValue]) -> usize
pub fn estimate_row(&self, values: &[SochValue]) -> usize
Estimate tokens for a row (multiple values)
Sourcepub fn estimate_header(
&self,
table: &str,
columns: &[String],
row_count: usize,
) -> usize
pub fn estimate_header( &self, table: &str, columns: &[String], row_count: usize, ) -> usize
Estimate tokens for a table header
Sourcepub fn estimate_table(
&self,
table: &str,
columns: &[String],
rows: &[Vec<SochValue>],
) -> usize
pub fn estimate_table( &self, table: &str, columns: &[String], rows: &[Vec<SochValue>], ) -> usize
Estimate tokens for a complete TOON table
Sourcepub fn estimate_text(&self, text: &str) -> usize
pub fn estimate_text(&self, text: &str) -> usize
Estimate tokens for plain text
Sourcepub fn truncate_to_tokens(&self, text: &str, max_tokens: usize) -> String
pub fn truncate_to_tokens(&self, text: &str, max_tokens: usize) -> String
Truncate text to fit within token budget
Uses binary search to find the optimal truncation point.
Trait Implementations§
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
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