Skip to content

Video To Text

Defines a base class for video-to-text converters used in Gen AI applications.

This module provides an abstract base class BaseVideoToText which defines a common interface for converting video content into text. It handles initial input validation and delegates the actual conversion process to a subclass implementation via the _convert method.

BaseVideoToText(transform=None, **kwargs)

Bases: BaseModalityConverter, ABC

Abstract base class for video-to-text conversion.

Subclasses must implement the _convert and from_preset methods.

Initialize the video to text converter.

Parameters:

Name Type Description Default
transform list[MediaToolkit] | None

Processor(s) to transform the video attachment.

None
**kwargs Any

Additional keyword arguments.

{}

convert(source, **kwargs) async

Execute the video 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 video 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 video.

Raises:

Type Description
ValueError

If source is an empty string or missing.

TypeError

If source is not a string or bytes.

from_preset(preset_name='default', **kwargs) abstractmethod classmethod

Initialize the video to text converter using preset model configurations.

This abstract classmethod must be implemented by subclasses to define how to create an instance from a preset configuration.

Parameters:

Name Type Description Default
preset_name str | None

Name of the preset to use. Defaults to "default".

'default'
**kwargs Any

Additional keyword arguments to pass to the preset configuration.

{}

Returns:

Name Type Description
BaseVideoToText Self

An initialized video to text converter using the specified preset model.

Raises:

Type Description
NotImplementedError

If the method is not implemented in a subclass.