Struct ContentPrioritizer

Source
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

Source

pub fn new() -> Result<Self>

Creates a new content prioritizer.

§Returns

A new ContentPrioritizer instance with an initialized token counter.

§Errors

Returns an error if the underlying token counter cannot be initialized.

Source

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 prioritize
  • max_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 first

Auto Trait Implementations§

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, 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.