pub struct TokenThresholdCompressor { /* private fields */ }Expand description
Compresses message history when the total character count exceeds max_chars.
Uses an LLM to produce a one-sentence summary that replaces the middle messages (keeping the system prompt and the last user message intact).
Implementations§
Source§impl TokenThresholdCompressor
impl TokenThresholdCompressor
Sourcepub fn new(
max_chars: usize,
llm: Arc<dyn Runnable<LlmRequest, LlmResponse>>,
) -> Self
pub fn new( max_chars: usize, llm: Arc<dyn Runnable<LlmRequest, LlmResponse>>, ) -> Self
max_chars / 4 approximates the token count.
Trait Implementations§
Source§impl ContextCompressor for TokenThresholdCompressor
impl ContextCompressor for TokenThresholdCompressor
Source§fn should_compress(&self, messages: &[Message]) -> bool
fn should_compress(&self, messages: &[Message]) -> bool
Return
true if the current message list should be compressed.Auto Trait Implementations§
impl Freeze for TokenThresholdCompressor
impl !RefUnwindSafe for TokenThresholdCompressor
impl Send for TokenThresholdCompressor
impl Sync for TokenThresholdCompressor
impl Unpin for TokenThresholdCompressor
impl UnsafeUnpin for TokenThresholdCompressor
impl !UnwindSafe for TokenThresholdCompressor
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