pub struct TokenUtils;Expand description
Token estimation utilities
Implementations§
Source§impl TokenUtils
impl TokenUtils
Sourcepub fn estimate_tokens(text: &str) -> u32
pub fn estimate_tokens(text: &str) -> u32
Estimate tokens for text (simple heuristic: ~4 chars/token)
Sourcepub fn estimate_cost(
prompt: &str,
estimated_completion_tokens: u32,
cost_per_1k_input: f64,
cost_per_1k_output: f64,
) -> f64
pub fn estimate_cost( prompt: &str, estimated_completion_tokens: u32, cost_per_1k_input: f64, cost_per_1k_output: f64, ) -> f64
Estimate cost for a request given pricing
Sourcepub fn exceeds_limit(text: &str, limit: u32) -> bool
pub fn exceeds_limit(text: &str, limit: u32) -> bool
Check if text is likely to exceed token limit
Sourcepub fn truncate_to_limit(text: &str, limit: u32) -> String
pub fn truncate_to_limit(text: &str, limit: u32) -> String
Truncate text to fit within token limit (rough approximation)
Auto Trait Implementations§
impl Freeze for TokenUtils
impl RefUnwindSafe for TokenUtils
impl Send for TokenUtils
impl Sync for TokenUtils
impl Unpin for TokenUtils
impl UnwindSafe for TokenUtils
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