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): Cleanup block names and add explicit block name check (#7709)
Zamil Majdyfe5c1968bcdf
diff --git a/rnd/autogpt_server/autogpt_server/blocks/__init__.py b/rnd/autogpt_server/autogpt_server/blocks/__init__.pyindex f177b60bd0..e2ac27bd1a 100644--- a/rnd/autogpt_server/autogpt_server/blocks/__init__.py+++ b/rnd/autogpt_server/autogpt_server/blocks/__init__.py@@ -1,6 +1,7 @@import globimport importlibimport os+import refrom pathlib import Pathfrom autogpt_server.data.block import Block@@ -15,6 +16,11 @@ modules = [if os.path.isfile(f) and f.endswith(".py") and not f.endswith("__init__.py")]for module in modules:+ if not re.match("^[a-z_]+$", module):+ raise ValueError(+ f"Block module {module} error: module name must be lowercase, separated by underscores, and contain only alphabet characters"+ )+importlib.import_module(f".{module}", package=__name__)AVAILABLE_MODULES.append(module)@@ -30,9 +36,16 @@ def all_subclasses(clz):for cls in all_subclasses(Block):- if not cls.__name__.endswith("Block"):+ name = cls.__name__++ if cls.__name__.endswith("Base"):continue+ if not cls.__name__.endswith("Block"):+ raise ValueError(+ f"Block class {cls.__name__} does not end with 'Block', If you are creating an abstract class, please name the class with 'Base' at the end"+ )+block = cls()if not isinstance(block.id, str) or len(block.id) != 36:diff --git a/rnd/autogpt_server/autogpt_server/blocks/if_block.py b/rnd/autogpt_server/autogpt_server/blocks/branching.pysimilarity index 100%rename from rnd/autogpt_server/autogpt_server/blocks/if_block.pyrename to rnd/autogpt_server/autogpt_server/blocks/branching.pydiff --git a/rnd/autogpt_server/autogpt_server/blocks/read_csv.py b/rnd/autogpt_server/autogpt_server/blocks/csv.pysimilarity index 100%rename from rnd/autogpt_server/autogpt_server/blocks/read_csv.pyrename to rnd/autogpt_server/autogpt_server/blocks/csv.pydiff --git a/rnd/autogpt_server/autogpt_server/blocks/discordblock.py b/rnd/autogpt_server/autogpt_server/blocks/discord.pysimilarity index 100%rename from rnd/autogpt_server/autogpt_server/blocks/discordblock.pyrename to rnd/autogpt_server/autogpt_server/blocks/discord.pydiff --git a/rnd/autogpt_server/autogpt_server/blocks/foreach_block.py b/rnd/autogpt_server/autogpt_server/blocks/iteration.pysimilarity index 100%rename from rnd/autogpt_server/autogpt_server/blocks/foreach_block.pyrename to rnd/autogpt_server/autogpt_server/blocks/iteration.pydiff --git a/rnd/autogpt_server/autogpt_server/blocks/create_medium_post.py b/rnd/autogpt_server/autogpt_server/blocks/medium.pysimilarity index 100%rename from rnd/autogpt_server/autogpt_server/blocks/create_medium_post.pyrename to rnd/autogpt_server/autogpt_server/blocks/medium.pydiff --git a/rnd/autogpt_server/autogpt_server/blocks/rss-reader-block.py b/rnd/autogpt_server/autogpt_server/blocks/rss.pysimilarity index 100%rename from rnd/autogpt_server/autogpt_server/blocks/rss-reader-block.pyrename to rnd/autogpt_server/autogpt_server/blocks/rss.pydiff --git a/rnd/autogpt_server/autogpt_server/blocks/search.py b/rnd/autogpt_server/autogpt_server/blocks/search.pyindex 46cd3b4867..21c457323b 100644--- a/rnd/autogpt_server/autogpt_server/blocks/search.py+++ b/rnd/autogpt_server/autogpt_server/blocks/search.py@@ -131,7 +131,7 @@ class WebScraperBlock(Block, GetRequest):yield "error", f"Request to Jina-ai Reader failed: {e}"-class GetOpenWeatherMapWeather(Block, GetRequest):+class GetOpenWeatherMapBlock(Block, GetRequest):class Input(BlockSchema):location: strapi_key: BlockSecret = SecretField(key="openweathermap_api_key")@@ -146,8 +146,8 @@ class GetOpenWeatherMapWeather(Block, GetRequest):def __init__(self):super().__init__(id="f7a8b2c3-6d4e-5f8b-9e7f-6d4e5f8b9e7f",- input_schema=GetOpenWeatherMapWeather.Input,- output_schema=GetOpenWeatherMapWeather.Output,+ input_schema=GetOpenWeatherMapBlock.Input,+ output_schema=GetOpenWeatherMapBlock.Output,test_input={"location": "New York","api_key": "YOUR_API_KEY",diff --git a/rnd/autogpt_server/autogpt_server/blocks/youtube_transcriber.py b/rnd/autogpt_server/autogpt_server/blocks/youtube.pysimilarity index 94%rename from rnd/autogpt_server/autogpt_server/blocks/youtube_transcriber.pyrename to rnd/autogpt_server/autogpt_server/blocks/youtube.pyindex 3085085514..91248152c0 100644--- a/rnd/autogpt_server/autogpt_server/blocks/youtube_transcriber.py+++ b/rnd/autogpt_server/autogpt_server/blocks/youtube.py@@ -7,7 +7,7 @@ from autogpt_server.data.block import Block, BlockOutput, BlockSchemafrom autogpt_server.data.model import SchemaField-class YouTubeTranscriber(Block):+class YouTubeTranscriberBlock(Block):class Input(BlockSchema):youtube_url: str = SchemaField(description="The URL of the YouTube video to transcribe",@@ -24,8 +24,8 @@ class YouTubeTranscriber(Block):def __init__(self):super().__init__(id="f3a8f7e1-4b1d-4e5f-9f2a-7c3d5a2e6b4c",- input_schema=YouTubeTranscriber.Input,- output_schema=YouTubeTranscriber.Output,+ input_schema=YouTubeTranscriberBlock.Input,+ output_schema=YouTubeTranscriberBlock.Output,test_input={"youtube_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"},test_output=[("video_id", "dQw4w9WgXcQ"),diff --git a/rnd/autogpt_server/autogpt_server/server/server.py b/rnd/autogpt_server/autogpt_server/server/server.pyindex 2fee638322..bc4d5ecaf5 100644--- a/rnd/autogpt_server/autogpt_server/server/server.py+++ b/rnd/autogpt_server/autogpt_server/server/server.py@@ -1,5 +1,4 @@import asyncio-import uuidfrom collections import defaultdictfrom contextlib import asynccontextmanagerfrom typing import Annotated, Any, Dict