AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(blocks): Add text decoder block (#8248)
Toran Bruce Richards723055ce1d9f
diff --git a/autogpt_platform/backend/backend/blocks/decoder_block.py b/autogpt_platform/backend/backend/blocks/decoder_block.pynew file mode 100644index 0000000000..fb23ef2c56--- /dev/null+++ b/autogpt_platform/backend/backend/blocks/decoder_block.py@@ -0,0 +1,42 @@+import codecs++from backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema+from backend.data.model import SchemaField+++class TextDecoderBlock(Block):+ class Input(BlockSchema):+ text: str = SchemaField(+ description="A string containing escaped characters to be decoded",+ placeholder='Your entire text block with \\n and \\" escaped characters',+ )++ class Output(BlockSchema):+ decoded_text: str = SchemaField(+ description="The decoded text with escape sequences processed"+ )++ def __init__(self):+ super().__init__(+ id="2570e8fe-8447-43ed-84c7-70d657923231",+ description="Decodes a string containing escape sequences into actual text",+ categories={BlockCategory.TEXT},+ input_schema=TextDecoderBlock.Input,+ output_schema=TextDecoderBlock.Output,+ test_input={"text": """Hello\nWorld!\nThis is a \"quoted\" string."""},+ test_output=[+ (+ "decoded_text",+ """Hello+World!+This is a "quoted" string.""",+ )+ ],+ )++ def run(self, input_data: Input, **kwargs) -> BlockOutput:+ try:+ decoded_text = codecs.decode(input_data.text, "unicode_escape")+ yield "decoded_text", decoded_text+ except Exception as e:+ yield "error", f"Error decoding text: {str(e)}"