fix(util.py): fix IndentationError while parsing from source code. (#944)

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-09-21 06:28:49 -03:00 committed by GitHub
commit 4c6cd57a1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,12 +1,13 @@
import ast
import inspect
import textwrap
from typing import Dict, Union
from langchain.agents.tools import Tool
def get_func_tool_params(func, **kwargs) -> Union[Dict, None]:
tree = ast.parse(inspect.getsource(func))
tree = ast.parse(textwrap.dedent(inspect.getsource(func)))
# Iterate over the statements in the abstract syntax tree
for node in ast.walk(tree):
@ -57,7 +58,7 @@ def get_func_tool_params(func, **kwargs) -> Union[Dict, None]:
def get_class_tool_params(cls, **kwargs) -> Union[Dict, None]:
tree = ast.parse(inspect.getsource(cls))
tree = ast.parse(textwrap.dedent(inspect.getsource(cls)))
tool_params = {}