Skip to content

Image To Text

Defines a base class for image to text converter used in Gen AI applications.

This module provides the foundation for converting images to text in various formats, including OCR, image captioning, and other image analysis tasks.

BaseImageToText()

Bases: BaseModalityConverter

An abstract base class for image to text conversion used in Gen AI applications.

This class provides a foundation for building image to text converter components in Gen AI applications. It supports various types of image sources (file paths, URLs, base64 strings) and can be extended to implement different types of image analysis tasks like OCR, captioning, or object detection.

Subclasses must implement the _convert method.

Initialize the base image to text component with logging capabilities.

convert(source, **kwargs) async

Execute the image to text conversion process.

This method validates the input parameters and delegates to _convert to perform the actual conversion.

Parameters:

Name Type Description Default
source str | bytes

The source of the image to convert to text.

required
**kwargs Any

Additional conversion parameters. Implementations may accept keyword arguments such as language, prompt, or provider-specific options.

{}

Returns:

Name Type Description
TextResult TextResult

The result of processing the image.

Raises:

Type Description
MediaInputInvalidError

If source has an unsupported Python type, is empty, or cannot be loaded as supported media.

MediaInputUnsupportedError

If the resolved media type or source form is not accepted by image-to-text conversion.

MediaSourceNotFoundError

If loading reports that the source does not exist.

MediaSourceAccessDeniedError

If the process cannot read the source.

MediaSourceReadTimeoutError

If loading exceeds its time limit.

MediaSourceReadError

If a source loader fails for another read-related reason.