MessageTransform

MessageTransform(*args, **kwargs)

Defines a contract for message transformation.
Classes implementing this protocol should provide an apply_transform method that takes a list of messages and returns the transformed list.

Parameters:
NameDescription
*args
**kwargs

Instance Methods

apply_transform

apply_transform(self, messages: list[dict[str, Any]]) -> list[dict[str, Any]]

Applies a transformation to a list of messages.

Parameters:
NameDescription
messagesA list of dictionaries representing messages.

Type: list[dict[str, typing.Any]]
Returns:
TypeDescription
list[dict[str, typing.Any]]A new list of dictionaries containing the transformed messages.

get_logs

get_logs(
    self,
    pre_transform_messages: list[dict[str, Any]],
    post_transform_messages: list[dict[str, Any]]
) -> tuple[str, bool]

Creates the string including the logs of the transformation

Alongside the string, it returns a boolean indicating whether the transformation had an effect or not.

Parameters:
NameDescription
pre_transform_messagesA list of dictionaries representing messages before the transformation.

Type: list[dict[str, typing.Any]]
post_transform_messagesA list of dictionaries representig messages after the transformation.

Type: list[dict[str, typing.Any]]
Returns:
TypeDescription
tuple[str, bool]A tuple with a string with the logs and a flag indicating whether the transformation had an effect or not.