diff --git a/autogpt_platform/backend/backend/blocks/encoder_block.py b/autogpt_platform/backend/backend/blocks/encoder_block.py index f0deec4909..d16125a36e 100644 --- a/autogpt_platform/backend/backend/blocks/encoder_block.py +++ b/autogpt_platform/backend/backend/blocks/encoder_block.py @@ -62,12 +62,7 @@ This is a "quoted" string."""}, **kwargs: Additional keyword arguments (unused). Yields: - The encoded text with escape sequences, or an error message on failure. + The encoded text with escape sequences. """ - try: - encoded_text = codecs.encode(input_data.text, "unicode_escape").decode( - "utf-8" - ) - yield "encoded_text", encoded_text - except Exception as e: - yield "error", f"Failed to encode text: {e}" + encoded_text = codecs.encode(input_data.text, "unicode_escape").decode("utf-8") + yield "encoded_text", encoded_text diff --git a/docs/integrations/block-integrations/encoder_block.md b/docs/integrations/block-integrations/encoder_block.md new file mode 100644 index 0000000000..139d321592 --- /dev/null +++ b/docs/integrations/block-integrations/encoder_block.md @@ -0,0 +1,37 @@ +# Text Encoder + +## What it is +A tool that converts text containing special characters into escaped text sequences. + +## What it does +It takes a string of text that contains special characters (like new lines or quotation marks) and converts them into their escape sequence representations (like '\n' for new lines). + +## How it works +The Text Encoder examines the input text and identifies special characters. It then replaces these characters with their escape sequence equivalents, making the text safe for storage or transmission in formats that don't support raw special characters. + +## Inputs +| Input | Description | +|-------|-------------| +| Text | The text you want to encode, which may contain special characters like new lines or quotation marks | + +## Outputs +| Output | Description | +|--------|-------------| +| Encoded Text | The text after processing, with all special characters converted to their escape sequences | + +## Possible use case +Imagine you have a piece of text with line breaks that you need to store in a JSON file or send through an API: + +``` +Hello +World! +This is a "quoted" string. +``` + +The Text Encoder can convert it into: + +``` +Hello\nWorld!\nThis is a "quoted" string. +``` + +This is useful when you need to prepare text for storage in formats that require escape sequences, or when sending data to systems that expect encoded text. It's the inverse operation of the Text Decoder block.