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

This commit is contained in:
Tiago Santos 2023-09-20 18:41:45 +01:00
commit 8a0630652f
No known key found for this signature in database
GPG key ID: 95AACA8C34370406

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 = {}