From c8a47dce4059871fa182fc948ab71191f4b744fe Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Wed, 12 Feb 2025 16:11:53 +0700 Subject: [PATCH 1/2] feat(block): Add batch matched result and its count on ExtractTextInformationBlock --- .../backend/backend/blocks/text.py | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/autogpt_platform/backend/backend/blocks/text.py b/autogpt_platform/backend/backend/blocks/text.py index b2ad5e77e111..10301d60c2c7 100644 --- a/autogpt_platform/backend/backend/blocks/text.py +++ b/autogpt_platform/backend/backend/blocks/text.py @@ -76,6 +76,8 @@ class Input(BlockSchema): class Output(BlockSchema): positive: str = SchemaField(description="Extracted text") negative: str = SchemaField(description="Original text") + matched_results: list[str] = SchemaField(description="List of matched results") + matched_count: int = SchemaField(description="Number of matched results") def __init__(self): super().__init__( @@ -104,12 +106,29 @@ def __init__(self): ], test_output=[ ("positive", "World!"), + ("matched_results", ["World!"]), + ("matched_count", 1), + ("positive", "Hello, World!"), + ("matched_results", ["Hello, World!"]), + ("matched_count", 1), + ("negative", "Hello, World!"), + ("matched_results", []), + ("matched_count", 0), + ("positive", "Hello,"), + ("matched_results", ["Hello,"]), + ("matched_count", 1), + ("positive", "World!!"), + ("matched_results", ["World!!"]), + ("matched_count", 1), + ("positive", "World!!"), ("positive", "Earth!!"), + ("matched_results", ["World!!", "Earth!!"]), + ("matched_count", 2), ], ) @@ -130,13 +149,16 @@ def run(self, input_data: Input, **kwargs) -> BlockOutput: for match in re.finditer(input_data.pattern, txt, flags) if input_data.group <= len(match.groups()) ] + if not input_data.find_all: + matches = matches[:1] for match in matches: yield "positive", match - if not input_data.find_all: - return if not matches: yield "negative", input_data.text + yield "matched_results", matches + yield "matched_count", len(matches) + class FillTextTemplateBlock(Block): class Input(BlockSchema): From fab644e7de371e6002a872eb12ed4d017bdf3783 Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Wed, 12 Feb 2025 16:14:28 +0700 Subject: [PATCH 2/2] Reformat --- autogpt_platform/backend/backend/blocks/text.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/autogpt_platform/backend/backend/blocks/text.py b/autogpt_platform/backend/backend/blocks/text.py index 10301d60c2c7..21351bbbd64e 100644 --- a/autogpt_platform/backend/backend/blocks/text.py +++ b/autogpt_platform/backend/backend/blocks/text.py @@ -105,26 +105,27 @@ def __init__(self): }, ], test_output=[ + # Test case 1 ("positive", "World!"), ("matched_results", ["World!"]), ("matched_count", 1), - + # Test case 2 ("positive", "Hello, World!"), ("matched_results", ["Hello, World!"]), ("matched_count", 1), - + # Test case 3 ("negative", "Hello, World!"), ("matched_results", []), ("matched_count", 0), - + # Test case 4 ("positive", "Hello,"), ("matched_results", ["Hello,"]), ("matched_count", 1), - + # Test case 5 ("positive", "World!!"), ("matched_results", ["World!!"]), ("matched_count", 1), - + # Test case 6 ("positive", "World!!"), ("positive", "Earth!!"), ("matched_results", ["World!!", "Earth!!"]),