diff --git a/autogpt_platform/backend/backend/blocks/code_extraction_block.py b/autogpt_platform/backend/backend/blocks/code_extraction_block.py new file mode 100644 index 000000000..ab1e35aa5 --- /dev/null +++ b/autogpt_platform/backend/backend/blocks/code_extraction_block.py @@ -0,0 +1,110 @@ +import re + +from backend.data.block import Block, BlockCategory, BlockOutput, BlockSchema +from backend.data.model import SchemaField + + +class CodeExtractionBlock(Block): + class Input(BlockSchema): + text: str = SchemaField( + description="Text containing code blocks to extract (e.g., AI response)", + placeholder="Enter text containing code blocks", + ) + + class Output(BlockSchema): + html: str = SchemaField(description="Extracted HTML code") + css: str = SchemaField(description="Extracted CSS code") + javascript: str = SchemaField(description="Extracted JavaScript code") + python: str = SchemaField(description="Extracted Python code") + sql: str = SchemaField(description="Extracted SQL code") + java: str = SchemaField(description="Extracted Java code") + cpp: str = SchemaField(description="Extracted C++ code") + csharp: str = SchemaField(description="Extracted C# code") + json_code: str = SchemaField(description="Extracted JSON code") + bash: str = SchemaField(description="Extracted Bash code") + php: str = SchemaField(description="Extracted PHP code") + ruby: str = SchemaField(description="Extracted Ruby code") + yaml: str = SchemaField(description="Extracted YAML code") + markdown: str = SchemaField(description="Extracted Markdown code") + typescript: str = SchemaField(description="Extracted TypeScript code") + xml: str = SchemaField(description="Extracted XML code") + remaining_text: str = SchemaField( + description="Remaining text after code extraction" + ) + + def __init__(self): + super().__init__( + id="d3a7d896-3b78-4f44-8b4b-48fbf4f0bcd8", + description="Extracts code blocks from text and identifies their programming languages", + categories={BlockCategory.TEXT}, + input_schema=CodeExtractionBlock.Input, + output_schema=CodeExtractionBlock.Output, + test_input={ + "text": "Here's a Python example:\n```python\nprint('Hello World')\n```\nAnd some HTML:\n```html\n