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]) -> list[dict]

Applies a transformation to a list of messages.

Parameters:
NameDescription
messagesA list of dictionaries representing messages.

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

get_logs

get_logs(
    self,
    pre_transform_messages: list[dict],
    post_transform_messages: list[dict]
) -> 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]
post_transform_messagesA list of dictionaries representig messages after the transformation.

Type: list[dict]
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.