Repository: Significant-Gravitas/Auto-GPT
File: rnd/autogpt_server/autogpt_server/blocks/basic.py (Python)

Code before:
            if len(obj) == 0:
                yield "output", []
            elif isinstance(obj[0], dict) and key in obj[0]:
                yield "output", [item[key] for item in obj if key in item]
            else:
                yield "output", [getattr(val, key) for val in obj if hasattr(val, key)]
        elif isinstance(obj, object) and isinstance(key, str) and hasattr(obj, key):
            yield "output", getattr(obj, key)
        else:
            yield "missing", input_data.input


T = TypeVar("T")


class InputOutputBlockInput(BlockSchema, Generic[T]):
    value: T = Field(description="The value to be passed as input/output.")
    name: str = Field(description="The name of the input/output.")


class InputOutputBlockOutput(BlockSchema, Generic[T]):
    result: T = Field(description="The value passed as input/output.")


class InputOutputBlockBase(Block, ABC, Generic[T]):
    @abstractmethod
    def block_id(self) -> str:
        pass

    def __init__(self, *args, **kwargs):
        input_schema = InputOutputBlockInput[T]
        output_schema = InputOutputBlockOutput[T]

        super().__init__(
            id=self.block_id(),
            description="This block is used to define the input & output of a graph.",
            input_schema=input_schema,
            output_schema=output_schema,
            test_input=[
                {"value": {"apple": 1, "banana": 2, "cherry": 3}, "name": "input_1"},
                {"value": MockObject(value="!!", key="key"), "name": "input_2"},
            ],
            test_output=[
                ("result", {"apple": 1, "banana": 2, "cherry": 3}),
                ("result", MockObject(value="!!", key="key")),
            ],
            static_output=True,
            *args,
            **kwargs,
        )


Review comment (suggestion):
The idea of this base class is allowing strong typing for input output.
Currently there is only Input[Any], but we definitely need Into put Strong input etc later for better UI display and type safety.

Code after:
                yield "output", []
            elif isinstance(obj[0], dict) and key in obj[0]:
                yield "output", [item[key] for item in obj if key in item]
            else:
                yield "output", [getattr(val, key) for val in obj if hasattr(val, key)]
        elif isinstance(obj, object) and isinstance(key, str) and hasattr(obj, key):
            yield "output", getattr(obj, key)
        else:
            yield "missing", input_data.input


class InputBlock(Block):
    """
    This block is used to provide input to the graph.

    It takes in a value, name, description, default values list and bool to limit selection to default values.

    It Outputs the value passed as input.
    """

    class Input(BlockSchema):
        value: Any = SchemaField(description="The value to be passed as input.")
        name: str = SchemaField(description="The name of the input.")
        description: str = SchemaField(description="The description of the input.")
        placeholder_values: List[Any] = SchemaField(
            description="The placeholder values to be passed as input."
        )
        limit_to_placeholder_values: bool = SchemaField(
            description="Whether to limit the selection to placeholder values.",
            default=False,
        )

    class Output(BlockSchema):
        result: Any = SchemaField(description="The value passed as input.")

    def __init__(self):
        super().__init__(
            id="c0a8e994-ebf1-4a9c-a4d8-89d09c86741b",
            description="This block is used to provide input to the graph.",
            input_schema=InputBlock.Input,
            output_schema=InputBlock.Output,
            test_input=[
                {
                    "value": "Hello, World!",
                    "name": "input_1",
                    "description": "This is a test input.",
                    "placeholder_values": [],
                    "limit_to_placeholder_values": False,
                },
                {
                    "value": "Hello, World!",