from resolver import block from blocks.base import BaseBlock @block(name="Revert_List", kind="data process") class RevertList(BaseBlock): """ Revert a list Example: ``` node = RevertList() print(node(["test 1", "text 2", "text 3"])) ``` Will output: ["test 3", "text 2", "text 1"] """ def __call__(self, array: list) -> list: return array[::-1] @block(name="Head_of_List", kind="data process") class HeadOfList(BaseBlock): """ Get the first element of a list Example: ``` node = HeadOfList() print(node(["test 1", "text 2", "text 3"])) ``` Will output: "test 1" """ def __call__(self, array: list) -> str: if len(array) > 0: return array[0] else: return None @block(name="Deduplicated_List", kind="data process") class UniqueList(BaseBlock): def __call__(self, array: list) -> list: return list(set(array)) @block(name="List_to_ConversationText_Private", kind="data process") class List2ConversationTextPrivate(BaseBlock): def __call__(self, messages: list) -> str: ms = [] for i, m in enumerate(messages): role = "asistant" if i % 2 == 0: role = "user" ms.append(f"{role}: {m}") return "\n".join(ms)