fix: replace union with 3.8 compliant syntax
This commit is contained in:
parent
32a15bf576
commit
64bc7c40ed
2 changed files with 6 additions and 6 deletions
|
|
@ -257,7 +257,7 @@ class PromptNode(Node):
|
||||||
def build(
|
def build(
|
||||||
self,
|
self,
|
||||||
force: bool = False,
|
force: bool = False,
|
||||||
tools: Optional[List[Node]] | Optional[List[ToolNode]] = None,
|
tools: Optional[Union[List[Node], List[ToolNode]]] = None,
|
||||||
) -> Any:
|
) -> Any:
|
||||||
if not self._built or force:
|
if not self._built or force:
|
||||||
# Check if it is a ZeroShotPrompt and needs a tool
|
# Check if it is a ZeroShotPrompt and needs a tool
|
||||||
|
|
@ -280,7 +280,7 @@ class ChainNode(Node):
|
||||||
def build(
|
def build(
|
||||||
self,
|
self,
|
||||||
force: bool = False,
|
force: bool = False,
|
||||||
tools: Optional[List[Node]] | Optional[List[ToolNode]] = None,
|
tools: Optional[Union[List[Node], List[ToolNode]]] = None,
|
||||||
) -> Any:
|
) -> Any:
|
||||||
if not self._built or force:
|
if not self._built or force:
|
||||||
# Check if the chain requires a PromptNode
|
# Check if the chain requires a PromptNode
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import ast
|
||||||
import importlib
|
import importlib
|
||||||
import inspect
|
import inspect
|
||||||
import re
|
import re
|
||||||
from typing import Dict, Optional
|
from typing import Dict, Optional, Union
|
||||||
|
|
||||||
from langchain.agents.load_tools import (
|
from langchain.agents.load_tools import (
|
||||||
_BASE_TOOLS,
|
_BASE_TOOLS,
|
||||||
|
|
@ -170,7 +170,7 @@ def get_tool_by_name(name: str):
|
||||||
return tools[name]
|
return tools[name]
|
||||||
|
|
||||||
|
|
||||||
def get_tool_params(tool, **kwargs) -> Dict | None:
|
def get_tool_params(tool, **kwargs) -> Union[Dict, None]:
|
||||||
# Parse the function code into an abstract syntax tree
|
# Parse the function code into an abstract syntax tree
|
||||||
# Define if it is a function or a class
|
# Define if it is a function or a class
|
||||||
if inspect.isfunction(tool):
|
if inspect.isfunction(tool):
|
||||||
|
|
@ -183,7 +183,7 @@ def get_tool_params(tool, **kwargs) -> Dict | None:
|
||||||
raise ValueError("Tool must be a function or class.")
|
raise ValueError("Tool must be a function or class.")
|
||||||
|
|
||||||
|
|
||||||
def get_func_tool_params(func, **kwargs) -> Dict | None:
|
def get_func_tool_params(func, **kwargs) -> Union[Dict, None]:
|
||||||
tree = ast.parse(inspect.getsource(func))
|
tree = ast.parse(inspect.getsource(func))
|
||||||
|
|
||||||
# Iterate over the statements in the abstract syntax tree
|
# Iterate over the statements in the abstract syntax tree
|
||||||
|
|
@ -226,7 +226,7 @@ def get_func_tool_params(func, **kwargs) -> Dict | None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_class_tool_params(cls, **kwargs) -> Dict | None:
|
def get_class_tool_params(cls, **kwargs) -> Union[Dict, None]:
|
||||||
tree = ast.parse(inspect.getsource(cls))
|
tree = ast.parse(inspect.getsource(cls))
|
||||||
|
|
||||||
tool_params = {}
|
tool_params = {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue