pub struct ContentPrioritizer { /* private fields */ }Expand description
Content prioritizer that manages sections based on priority and token limits.
The prioritizer sorts content sections by priority and ensures the total content fits within specified token limits by truncating lower priority sections when necessary.
§Examples
use ai_context_gen::token_counter::{ContentPrioritizer, ContentSection};
let prioritizer = ContentPrioritizer::new().unwrap();
let sections = vec![
ContentSection::new("High Priority".to_string(), "Content...".to_string(), 10),
ContentSection::new("Low Priority".to_string(), "More content...".to_string(), 1),
];
let prioritized = prioritizer.prioritize_content(sections, 1000);Implementations§
Source§impl ContentPrioritizer
impl ContentPrioritizer
Sourcepub fn prioritize_content(
&self,
sections: Vec<ContentSection>,
max_tokens: usize,
) -> Vec<ContentSection>
pub fn prioritize_content( &self, sections: Vec<ContentSection>, max_tokens: usize, ) -> Vec<ContentSection>
Prioritizes and truncates content sections to fit within token limits.
Sorts sections by priority (highest first) and includes as many complete sections as possible. When a section would exceed the token limit, it attempts to truncate it if there are sufficient remaining tokens.
§Arguments
sections- List of content sections to prioritizemax_tokens- Maximum total tokens allowed
§Returns
A vector of sections that fit within the token limit, sorted by priority.
§Examples
use ai_context_gen::token_counter::{ContentPrioritizer, ContentSection};
let prioritizer = ContentPrioritizer::new().unwrap();
let sections = vec![
ContentSection::new("Important".to_string(), "Critical info".to_string(), 10),
ContentSection::new("Less Important".to_string(), "Extra details".to_string(), 5),
];
let result = prioritizer.prioritize_content(sections, 100);
// Higher priority sections appear firstAuto Trait Implementations§
impl Freeze for ContentPrioritizer
impl RefUnwindSafe for ContentPrioritizer
impl Send for ContentPrioritizer
impl Sync for ContentPrioritizer
impl Unpin for ContentPrioritizer
impl UnwindSafe for ContentPrioritizer
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