pub struct ImageTokenCounter { /* private fields */ }Expand description
Image token counting for different providers.
Different AI providers count image tokens differently:
- OpenAI: ~85 tokens base + variable based on resolution
- Anthropic: ~1600 tokens per image
- Google: ~258 tokens per image
- Ollama: ~100 tokens per image (estimate)
Implementations§
Source§impl ImageTokenCounter
impl ImageTokenCounter
Sourcepub fn with_counter(token_counter: Arc<TokenCounter>) -> Self
pub fn with_counter(token_counter: Arc<TokenCounter>) -> Self
Create with an existing token counter.
Sourcepub fn count_image_tokens(
&self,
metadata: &ImageMetadata,
provider_name: &str,
model: &str,
) -> ImageResult<usize>
pub fn count_image_tokens( &self, metadata: &ImageMetadata, provider_name: &str, model: &str, ) -> ImageResult<usize>
Sourcepub fn count_multiple_image_tokens(
&self,
images: &[ImageMetadata],
provider_name: &str,
model: &str,
) -> ImageResult<usize>
pub fn count_multiple_image_tokens( &self, images: &[ImageMetadata], provider_name: &str, model: &str, ) -> ImageResult<usize>
Sourcepub fn count_prompt_tokens(
&self,
prompt: &str,
model: &str,
) -> ImageResult<usize>
pub fn count_prompt_tokens( &self, prompt: &str, model: &str, ) -> ImageResult<usize>
Count tokens for image analysis prompt.
This counts tokens for the analysis prompt text that accompanies the image.
Sourcepub fn count_total_tokens(
&self,
metadata: &ImageMetadata,
prompt: &str,
provider_name: &str,
model: &str,
) -> ImageResult<usize>
pub fn count_total_tokens( &self, metadata: &ImageMetadata, prompt: &str, provider_name: &str, model: &str, ) -> ImageResult<usize>
Sourcepub fn token_counter(&self) -> &TokenCounter
pub fn token_counter(&self) -> &TokenCounter
Get the underlying token counter.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ImageTokenCounter
impl RefUnwindSafe for ImageTokenCounter
impl Send for ImageTokenCounter
impl Sync for ImageTokenCounter
impl Unpin for ImageTokenCounter
impl UnwindSafe for ImageTokenCounter
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().