Repository: Significant-Gravitas/Auto-GPT
File: autogpt_platform/backend/backend/blocks/__init__.py (Python)

Code before:
        raise ValueError(f"Block ID {block.name} error: {block.id} is already in use")

    input_schema = block.input_schema.model_fields
    output_schema = block.output_schema.model_fields

    # Prevent duplicate field name in input_schema and output_schema
    duplicate_field_names = set(input_schema.keys()) & set(output_schema.keys())
    if duplicate_field_names:
        raise ValueError(
            f"{block.name} has duplicate field names in input_schema and output_schema: {duplicate_field_names}"
        )

    # Make sure `error` field is a string in the output schema
    if "error" in output_schema and output_schema["error"].annotation is not str:
        raise ValueError(
            f"{block.name} `error` field in output_schema must be a string"
        )

    for field in block.input_schema.model_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")

    if block.disabled:
        continue

    AVAILABLE_BLOCKS[block.id] = cls

__all__ = ["AVAILABLE_MODULES", "AVAILABLE_BLOCKS"]


Review comment (suggestion):
Any changes other than the one in llm.py, is simply propagating this change:
Making this global variable holding type classes instead of object.

Code after:
        raise ValueError(f"Block ID {block.name} error: {block.id} is not a valid UUID")

    if block.id in AVAILABLE_BLOCKS:
        raise ValueError(f"Block ID {block.name} error: {block.id} is already in use")

    input_schema = block.input_schema.model_fields
    output_schema = block.output_schema.model_fields

    # Prevent duplicate field name in input_schema and output_schema
    duplicate_field_names = set(input_schema.keys()) & set(output_schema.keys())
    if duplicate_field_names:
        raise ValueError(
            f"{block.name} has duplicate field names in input_schema and output_schema: {duplicate_field_names}"
        )

    # Make sure `error` field is a string in the output schema
    if "error" in output_schema and output_schema["error"].annotation is not str:
        raise ValueError(
            f"{block.name} `error` field in output_schema must be a string"
        )

    # Make sure all fields in input_schema and output_schema are annotated and has a value
    for field_name, field in [*input_schema.items(), *output_schema.items()]:
        if field.annotation is None:
            raise ValueError(
                f"{block.name} has a field {field_name} that is not annotated"
            )
        if field.json_schema_extra is None:
            raise ValueError(
                f"{block.name} has a field {field_name} not defined as SchemaField"
            )

    for field in block.input_schema.model_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")

    if block.disabled:
        continue

    AVAILABLE_BLOCKS[block.id] = block_cls

__all__ = ["AVAILABLE_MODULES", "AVAILABLE_BLOCKS"]