diff --git a/rnd/autogpt_server/autogpt_server/blocks/block.py b/rnd/autogpt_server/autogpt_server/blocks/block.py index 168460fabfe8..cedb13c03934 100644 --- a/rnd/autogpt_server/autogpt_server/blocks/block.py +++ b/rnd/autogpt_server/autogpt_server/blocks/block.py @@ -50,10 +50,11 @@ def run(self, input_data: Input) -> BlockOutput: block_dir = os.path.dirname(__file__) file_path = f"{block_dir}/{file_name}.py" module_name = f"autogpt_server.blocks.{file_name}" - with open(file_path, "w") as f: - f.write(code) try: + with open(file_path, "w") as f: + f.write(code) + module = __import__(module_name, fromlist=[class_name]) block_class: Type[Block] = getattr(module, class_name) block = block_class() @@ -62,3 +63,4 @@ def run(self, input_data: Input) -> BlockOutput: except Exception as e: os.remove(file_path) yield "error", f"[Code]\n{code}\n\n[Error]\n{str(e)}" +