From d5c3c5a14747afa3759ccdbf6bdb2a43e59fbb38 Mon Sep 17 00:00:00 2001 From: yzlin Date: Wed, 27 Mar 2024 20:08:11 +0800 Subject: [PATCH] rm unnecessary condition --- metagpt/tools/tool_convert.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/metagpt/tools/tool_convert.py b/metagpt/tools/tool_convert.py index 7d7374fdea..829269b1b2 100644 --- a/metagpt/tools/tool_convert.py +++ b/metagpt/tools/tool_convert.py @@ -32,15 +32,8 @@ def convert_code_to_tool_schema(obj, include: list[str] = None) -> dict: def convert_code_to_tool_schema_ast(code: str) -> list[dict]: """Converts a code string to a list of tool schemas by parsing the code with AST""" - # Modify the AST nodes to include parent references, enabling to attach methods to their class - def add_parent_references(node, parent=None): - for child in ast.iter_child_nodes(node): - child.parent = parent - add_parent_references(child, parent=node) - visitor = CodeVisitor(code) parsed_code = ast.parse(code) - add_parent_references(parsed_code) visitor.visit(parsed_code) return visitor.get_tool_schemas() @@ -108,7 +101,7 @@ def visit_AsyncFunctionDef(self, node): self._visit_function(node) def _visit_function(self, node): - if isinstance(node.parent, ast.ClassDef) or node.name.startswith("_"): + if node.name.startswith("_"): return function_schemas = self._get_function_schemas(node) function_schemas["code"] = ast.get_source_segment(self.source_code, node)