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

Code before:
        user_agent=creds.user_agent,
    )
    me = client.user.me()
    if not me:
        raise ValueError("Invalid Reddit credentials.")
    print(f"Logged in as Reddit user: {me.name}")
    return client


class GetRedditPostsBlock(Block):
    class Input(BlockSchema):
        subreddit: str = Field(description="Subreddit name")
        creds: RedditCredentials = Field(
            description="Reddit credentials",
            default=RedditCredentials(),
        )
        last_minutes: int | None = Field(
            description="Post time to stop minutes ago while fetching posts",
            default=None,
        )
        last_post: str | None = Field(
            description="Post ID to stop when reached while fetching posts",
            default=None,
        )
        post_limit: int | None = Field(
            description="Number of posts to fetch", default=10
        )

    class Output(BlockSchema):
        post: RedditPost = Field(description="Reddit post")

    def __init__(self):
        super().__init__(
            id="c6731acb-4285-4ee1-bc9b-03d0766c370f",
            description="This block fetches Reddit posts from a defined subreddit name.",
            categories={BlockCategory.SOCIAL},
            input_schema=GetRedditPostsBlock.Input,
            output_schema=GetRedditPostsBlock.Output,
            test_input={
                "creds": {
                    "client_id": "client_id",
                    "client_secret": "client_secret",
                    "username": "username",
                    "password": "password",
                    "user_agent": "user_agent",
                },
                "subreddit": "subreddit",
                "last_post": "id3",
                "post_limit": 2,
            },
            test_output=[

Review comment (suggestion):
should these be `| None` since they have a default

Code after:
        user_agent=creds.user_agent,
    )
    me = client.user.me()
    if not me:
        raise ValueError("Invalid Reddit credentials.")
    print(f"Logged in as Reddit user: {me.name}")
    return client


class GetRedditPostsBlock(Block):
    class Input(BlockSchema):
        subreddit: str = SchemaField(description="Subreddit name")
        creds: RedditCredentials = SchemaField(
            description="Reddit credentials",
            default=RedditCredentials(),
        )
        last_minutes: int | None = SchemaField(
            description="Post time to stop minutes ago while fetching posts",
            default=None,
        )
        last_post: str | None = SchemaField(
            description="Post ID to stop when reached while fetching posts",
            default=None,
        )
        post_limit: int | None = SchemaField(
            description="Number of posts to fetch", default=10
        )

    class Output(BlockSchema):
        post: RedditPost = SchemaField(description="Reddit post")

    def __init__(self):
        super().__init__(
            id="c6731acb-4285-4ee1-bc9b-03d0766c370f",
            description="This block fetches Reddit posts from a defined subreddit name.",
            categories={BlockCategory.SOCIAL},
            input_schema=GetRedditPostsBlock.Input,
            output_schema=GetRedditPostsBlock.Output,
            test_input={
                "creds": {
                    "client_id": "client_id",
                    "client_secret": "client_secret",
                    "username": "username",
                    "password": "password",
                    "user_agent": "user_agent",
                },
                "subreddit": "subreddit",
                "last_post": "id3",
                "post_limit": 2,
            },
            test_output=[