pub struct FixedTokenCounter {
pub per_char: usize,
pub per_block: usize,
}Expand description
Charges a fixed number of tokens per block and per character.
The second implementation, and the one tests want: a budget test that has to reach a compaction threshold should say so in one line rather than by generating enough prose to trip a real tokenizer, and a test asserting which strategy ran should not change its answer when the tokenizer’s table does.
Fields§
§per_char: usize§per_block: usizeImplementations§
Trait Implementations§
Source§impl TokenCounter for FixedTokenCounter
impl TokenCounter for FixedTokenCounter
Source§fn count_text(&self, text: &str) -> usize
fn count_text(&self, text: &str) -> usize
Tokens in a plain string.
Source§fn count_block(&self, block: &ModelContentBlock) -> usize
fn count_block(&self, block: &ModelContentBlock) -> usize
Tokens in one content block, including whatever that block type costs
beyond its text.
Source§fn count_messages(&self, messages: &[ModelMessage]) -> usize
fn count_messages(&self, messages: &[ModelMessage]) -> usize
Tokens in a conversation. Read more
Auto Trait Implementations§
impl Forget for FixedTokenCounter
impl Freeze for FixedTokenCounter
impl Move for FixedTokenCounter
impl RefUnwindSafe for FixedTokenCounter
impl Send for FixedTokenCounter
impl Sync for FixedTokenCounter
impl Unpin for FixedTokenCounter
impl UnsafeUnpin for FixedTokenCounter
impl UnwindSafe for FixedTokenCounter
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