Skip to content

Commit

Permalink
Merge pull request geekan#1169 from garylin2099/di_fixes
Browse files Browse the repository at this point in the history
rm unnecessary condition
  • Loading branch information
garylin2099 authored Apr 9, 2024
2 parents 02e0eb0 + d5c3c5a commit 6c2b238
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions metagpt/tools/tool_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6c2b238

Please sign in to comment.