Skip to content

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.

fix(rnd): avoid duplicating name on input/output pin for blocks (#7979)

Zamil Majdy70fab8711acc
diff --git a/rnd/autogpt_server/autogpt_server/blocks/__init__.py b/rnd/autogpt_server/autogpt_server/blocks/__init__.py
index 4c9c9c6572..789fd6aa29 100644
--- a/rnd/autogpt_server/autogpt_server/blocks/__init__.py
+++ b/rnd/autogpt_server/autogpt_server/blocks/__init__.py
@@ -54,6 +54,15 @@ for cls in all_subclasses(Block):
if block.id in AVAILABLE_BLOCKS:
raise ValueError(f"Block ID {block.name} error: {block.id} is already in use")
+ # Prevent duplicate field name in input_schema and output_schema
+ duplicate_field_names = set(block.input_schema.__fields__.keys()) & set(
+ block.output_schema.__fields__.keys()
+ )
+ if duplicate_field_names:
+ raise ValueError(
+ f"{block.name} has duplicate field names in input_schema and output_schema: {duplicate_field_names}"
+ )
+
for field in block.input_schema.__fields__.values():
if field.annotation is bool and field.default not in (True, False):
raise ValueError(f"{block.name} has a boolean field with no default value")
diff --git a/rnd/autogpt_server/autogpt_server/blocks/basic.py b/rnd/autogpt_server/autogpt_server/blocks/basic.py
index 3d5587c333..6838f73c7d 100644
--- a/rnd/autogpt_server/autogpt_server/blocks/basic.py
+++ b/rnd/autogpt_server/autogpt_server/blocks/basic.py
@@ -140,7 +140,7 @@ class InputOutputBlockInput(BlockSchema, Generic[T]):
class InputOutputBlockOutput(BlockSchema, Generic[T]):
- value: T = Field(description="The value passed as input/output.")
+ result: T = Field(description="The value passed as input/output.")
class InputOutputBlockBase(Block, ABC, Generic[T]):
@@ -162,8 +162,8 @@ class InputOutputBlockBase(Block, ABC, Generic[T]):
{"value": MockObject(value="!!", key="key"), "name": "input_2"},
],
test_output=[
- ("value", {"apple": 1, "banana": 2, "cherry": 3}),
- ("value", MockObject(value="!!", key="key")),
+ ("result", {"apple": 1, "banana": 2, "cherry": 3}),
+ ("result", MockObject(value="!!", key="key")),
],
static_output=True,
*args,
@@ -171,7 +171,7 @@ class InputOutputBlockBase(Block, ABC, Generic[T]):
)
def run(self, input_data: InputOutputBlockInput[T]) -> BlockOutput:
- yield "value", input_data.value
+ yield "result", input_data.value
class InputBlock(InputOutputBlockBase[Any]):
diff --git a/rnd/autogpt_server/autogpt_server/blocks/medium.py b/rnd/autogpt_server/autogpt_server/blocks/medium.py
index a918165cfd..d352f8fa12 100644
--- a/rnd/autogpt_server/autogpt_server/blocks/medium.py
+++ b/rnd/autogpt_server/autogpt_server/blocks/medium.py
@@ -57,7 +57,6 @@ class PublishToMediumBlock(Block):
class Output(BlockSchema):
post_id: str = SchemaField(description="The ID of the created Medium post")
post_url: str = SchemaField(description="The URL of the created Medium post")
- author_id: str = SchemaField(description="The Medium user ID of the author")
published_at: int = SchemaField(
description="The timestamp when the post was published"
)
@@ -85,7 +84,6 @@ class PublishToMediumBlock(Block):
test_output=[
("post_id", "e6f36a"),
("post_url", "https://medium.com/@username/test-post-e6f36a"),
- ("author_id", "1234567890abcdef"),
("published_at", 1626282600),
],
test_mock={
@@ -156,7 +154,6 @@ class PublishToMediumBlock(Block):
if "data" in response:
yield "post_id", response["data"]["id"]
yield "post_url", response["data"]["url"]
- yield "author_id", response["data"]["authorId"]
yield "published_at", response["data"]["publishedAt"]
else:
error_message = response.get("errors", [{}])[0].get(
diff --git a/rnd/autogpt_server/autogpt_server/blocks/time_blocks.py b/rnd/autogpt_server/autogpt_server/blocks/time_blocks.py
index 7ce9cdc8a8..10272e0b17 100644
--- a/rnd/autogpt_server/autogpt_server/blocks/time_blocks.py
+++ b/rnd/autogpt_server/autogpt_server/blocks/time_blocks.py
@@ -103,14 +103,14 @@ class GetCurrentDateAndTimeBlock(Block):
class CountdownTimerBlock(Block):
class Input(BlockSchema):
- message: Any = "timer finished"
+ input_message: Any = "timer finished"
seconds: Union[int, str] = 0
minutes: Union[int, str] = 0
hours: Union[int, str] = 0
days: Union[int, str] = 0
class Output(BlockSchema):
- message: str
+ output_message: str
def __init__(self):
super().__init__(
@@ -121,11 +121,11 @@ class CountdownTimerBlock(Block):
output_schema=CountdownTimerBlock.Output,
test_input=[
{"seconds": 1},
- {"message": "Custom message"},
+ {"input_message": "Custom message"},
],
test_output=[
- ("message", "timer finished"),
- ("message", "Custom message"),
+ ("output_message", "timer finished"),
+ ("output_message", "Custom message"),
],
)
@@ -139,4 +139,4 @@ class CountdownTimerBlock(Block):
total_seconds = seconds + minutes * 60 + hours * 3600 + days * 86400
time.sleep(total_seconds)
- yield "message", input_data.message
+ yield "output_message", input_data.input_message
diff --git a/rnd/autogpt_server/autogpt_server/usecases/sample.py b/rnd/autogpt_server/autogpt_server/usecases/sample.py
index a882345099..a4ec519a04 100644
--- a/rnd/autogpt_server/autogpt_server/usecases/sample.py
+++ b/rnd/autogpt_server/autogpt_server/usecases/sample.py
@@ -48,13 +48,13 @@ def create_test_graph() -> graph.Graph:
graph.Link(
source_id=nodes[0].id,
sink_id=nodes[2].id,
- source_name="value",
+ source_name="result",
sink_name="values_#_a",
),
graph.Link(
source_id=nodes[1].id,
sink_id=nodes[2].id,
- source_name="value",
+ source_name="result",
sink_name="values_#_b",
),
graph.Link(
diff --git a/rnd/autogpt_server/test/executor/test_manager.py b/rnd/autogpt_server/test/executor/test_manager.py
index 07b2b235d5..151b641bbc 100644
--- a/rnd/autogpt_server/test/executor/test_manager.py
+++ b/rnd/autogpt_server/test/executor/test_manager.py
@@ -39,7 +39,7 @@ async def assert_sample_graph_executions(
test_graph.id, graph_exec_id, test_user.id
)
- output_list = [{"value": ["Hello"]}, {"value": ["World"]}]
+ output_list = [{"result": ["Hello"]}, {"result": ["World"]}]
input_list = [
{"value": "Hello", "name": "input_1"},
{"value": "World", "name": "input_2"},