pub struct ContextTokenEngine(/* private fields */);Expand description
Cheaply cloneable token engine shared across the context subsystem. All token counting and truncation goes through this single object — pressure, compression, and render use the same backend.
Implementations§
Source§impl ContextTokenEngine
impl ContextTokenEngine
pub fn char_approx() -> Self
pub fn count(&self, text: &str) -> u32
pub fn truncate<'a>(&self, text: &'a str, max_tokens: u32) -> &'a str
pub fn token_budget_to_bytes(&self, tokens: u32) -> usize
pub fn count_message(&self, msg: &Message) -> u32
Sourcepub fn truncate_message(&self, msg: &Message, max_tokens: u32) -> Message
pub fn truncate_message(&self, msg: &Message, max_tokens: u32) -> Message
Truncate a text message to max_tokens. Returns the message unchanged
if it fits. Parts messages are never truncated — mangling structured
content produces worse outcomes than a minor token overrun.
Trait Implementations§
Source§impl Clone for ContextTokenEngine
impl Clone for ContextTokenEngine
Source§fn clone(&self) -> ContextTokenEngine
fn clone(&self) -> ContextTokenEngine
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for ContextTokenEngine
impl !UnwindSafe for ContextTokenEngine
impl Freeze for ContextTokenEngine
impl Send for ContextTokenEngine
impl Sync for ContextTokenEngine
impl Unpin for ContextTokenEngine
impl UnsafeUnpin for ContextTokenEngine
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