pub struct ImageAnalyzer { /* private fields */ }Expand description
Analyzes images using configured AI providers.
Implementations§
Source§impl ImageAnalyzer
impl ImageAnalyzer
Sourcepub fn new() -> ImageResult<Self>
pub fn new() -> ImageResult<Self>
Create a new image analyzer with default configuration.
Sourcepub fn with_config(config: ImageConfig) -> Self
pub fn with_config(config: ImageConfig) -> Self
Create a new image analyzer with custom configuration.
Sourcepub async fn analyze(
&self,
metadata: &ImageMetadata,
provider: &dyn Provider,
image_data: &[u8],
) -> ImageResult<ImageAnalysisResult>
pub async fn analyze( &self, metadata: &ImageMetadata, provider: &dyn Provider, image_data: &[u8], ) -> ImageResult<ImageAnalysisResult>
Analyze an image using the provided provider.
§Arguments
metadata- Image metadata including path, format, and dimensionsprovider- The AI provider to use for analysisimage_data- The raw image data (bytes)
§Returns
Analysis result with provider response and token usage
§Errors
Returns error if analysis fails after retries or if image is too large
Sourcepub async fn analyze_multiple(
&self,
images: Vec<(ImageMetadata, Vec<u8>)>,
provider: &dyn Provider,
) -> Vec<ImageResult<ImageAnalysisResult>> ⓘ
pub async fn analyze_multiple( &self, images: Vec<(ImageMetadata, Vec<u8>)>, provider: &dyn Provider, ) -> Vec<ImageResult<ImageAnalysisResult>> ⓘ
Sourcepub fn count_image_tokens(
&self,
metadata: &ImageMetadata,
model: &str,
) -> ImageResult<usize>
pub fn count_image_tokens( &self, metadata: &ImageMetadata, model: &str, ) -> ImageResult<usize>
Count tokens for an image based on provider and model.
Different providers have different token counting for images:
- OpenAI: ~85 tokens per image + variable tokens based on resolution
- Anthropic: ~1600 tokens per image
- Google: ~258 tokens per image
- Ollama: ~100 tokens per image (estimate)
Sourcepub fn config(&self) -> &ImageConfig
pub fn config(&self) -> &ImageConfig
Get the configuration used by this analyzer.
Sourcepub fn token_counter(&self) -> &TokenCounter
pub fn token_counter(&self) -> &TokenCounter
Get the token counter used by this analyzer.
Sourcepub async fn retry_analysis(
&self,
context: AnalysisRetryContext,
provider: &dyn Provider,
) -> ImageResult<ImageAnalysisResult>
pub async fn retry_analysis( &self, context: AnalysisRetryContext, provider: &dyn Provider, ) -> ImageResult<ImageAnalysisResult>
Retry analysis for a previously failed image.
This allows users to retry analysis without reloading the image. The image data is preserved in the retry context.
§Arguments
context- Retry context with preserved image dataprovider- The AI provider to use for analysis
§Returns
Analysis result or error with actionable message
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ImageAnalyzer
impl RefUnwindSafe for ImageAnalyzer
impl Send for ImageAnalyzer
impl Sync for ImageAnalyzer
impl Unpin for ImageAnalyzer
impl UnwindSafe for ImageAnalyzer
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().