From f4a3ff2261ca942cf57c29adbb44441ccd9a31c4 Mon Sep 17 00:00:00 2001 From: shenchucheng Date: Sat, 10 Aug 2024 17:08:41 +0800 Subject: [PATCH] ignore OSError when inspect.getsource call --- metagpt/tools/tool_registry.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/metagpt/tools/tool_registry.py b/metagpt/tools/tool_registry.py index 65d2fb662..49820b458 100644 --- a/metagpt/tools/tool_registry.py +++ b/metagpt/tools/tool_registry.py @@ -7,6 +7,7 @@ """ from __future__ import annotations +import contextlib import inspect import os from collections import defaultdict @@ -99,7 +100,9 @@ def register_tool(tags: list[str] = None, schema_path: str = "", **kwargs): if "metagpt" in file_path: # split to handle ../metagpt/metagpt/tools/... where only metapgt/tools/... is needed file_path = "metagpt" + file_path.split("metagpt")[-1] - source_code = inspect.getsource(cls) + source_code = "" + with contextlib.suppress(OSError): + source_code = inspect.getsource(cls) TOOL_REGISTRY.register_tool( tool_name=cls.__name__,