Skip to main content

ContextCompressor

Struct ContextCompressor 

Source
pub struct ContextCompressor<F, Fut>
where F: Fn(String) -> Fut + Send + Sync, Fut: Future<Output = Result<String, String>> + Send,
{
Show 21 fields pub context_length: usize, pub summarize_callback: F, pub threshold_percent: f64, pub protect_first_n: usize, pub protect_last_n: usize, pub summary_target_ratio: f64, pub abort_on_summary_failure: bool, pub threshold_tokens: usize, pub tail_token_budget: usize, pub max_summary_tokens: usize, pub compression_count: usize, pub last_prompt_tokens: usize, pub last_completion_tokens: usize, pub previous_summary: Option<String>, pub last_compression_savings_pct: f64, pub ineffective_compression_count: usize, pub summary_failure_cooldown_until: f64, pub last_summary_error: Option<String>, pub last_summary_dropped_count: usize, pub last_summary_fallback_used: bool, pub last_compress_aborted: bool,
}

Fields§

§context_length: usize§summarize_callback: F§threshold_percent: f64§protect_first_n: usize§protect_last_n: usize§summary_target_ratio: f64§abort_on_summary_failure: bool§threshold_tokens: usize§tail_token_budget: usize§max_summary_tokens: usize§compression_count: usize§last_prompt_tokens: usize§last_completion_tokens: usize§previous_summary: Option<String>§last_compression_savings_pct: f64§ineffective_compression_count: usize§summary_failure_cooldown_until: f64§last_summary_error: Option<String>§last_summary_dropped_count: usize§last_summary_fallback_used: bool§last_compress_aborted: bool

Implementations§

Source§

impl<F, Fut> ContextCompressor<F, Fut>
where F: Fn(String) -> Fut + Send + Sync, Fut: Future<Output = Result<String, String>> + Send,

Source

pub fn new( context_length: usize, summarize_callback: F, threshold_percent: Option<f64>, protect_first_n: Option<usize>, protect_last_n: Option<usize>, summary_target_ratio: Option<f64>, abort_on_summary_failure: Option<bool>, ) -> Self

Source

pub fn on_session_reset(&mut self)

Source

pub fn should_compress(&self, prompt_tokens: Option<usize>) -> bool

Source

pub fn has_content_to_compress(&self, messages: &[Message]) -> bool

Source

pub async fn compress( &mut self, messages: &[Message], current_tokens: Option<usize>, focus_topic: Option<&str>, force: bool, ) -> Vec<Message>

Auto Trait Implementations§

§

impl<F, Fut> Freeze for ContextCompressor<F, Fut>
where F: Freeze,

§

impl<F, Fut> RefUnwindSafe for ContextCompressor<F, Fut>
where F: RefUnwindSafe,

§

impl<F, Fut> Send for ContextCompressor<F, Fut>

§

impl<F, Fut> Sync for ContextCompressor<F, Fut>

§

impl<F, Fut> Unpin for ContextCompressor<F, Fut>
where F: Unpin,

§

impl<F, Fut> UnsafeUnpin for ContextCompressor<F, Fut>
where F: UnsafeUnpin,

§

impl<F, Fut> UnwindSafe for ContextCompressor<F, Fut>
where F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.