Skip to content

Modality transformer

Base any modality transformer.

BaseModalityTransformer

Bases: Component, ABC

An abstract base class for the modality transformers used in Gen AI applications.

Using the implementations of this class, users can transform a any source into a specific string/bytes. Each modality transformer comes with a default extractor function that extracts the source. Users can also supply their own extractor function to customize the extraction process.

transform(source, query=None, **kwargs) abstractmethod async

Transforms the given any modality source into a string or bytes.

This abstract method must be implemented by subclasses to define how the input source is transformed.

Parameters:

Name Type Description Default
source bytes | str | dict[str, bytes | str]

Any modality source, dict of any modality source to be transformed.

required
query str | None

Input query that will be used as additional information for modality transformation.

None
kwargs Any

additional args for transformer.

{}

Returns:

Name Type Description
TransformResult TransformResult

A string or bytes of transformed str or bytes source(s).

Raises:

Type Description
NotImplementedError

If the method is not implemented in a subclass.