Skip to content

Commit

Permalink
feat(block): Add batch matched result and its count on ExtractTextInf…
Browse files Browse the repository at this point in the history
…ormationBlock
  • Loading branch information
majdyz committed Feb 12, 2025
1 parent d050a3f commit c8a47dc
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions autogpt_platform/backend/backend/blocks/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down Expand Up @@ -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),
],
)

Expand All @@ -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):
Expand Down

0 comments on commit c8a47dc

Please sign in to comment.