Fix tool bug (#137)
This commit is contained in:
commit
99a612e66f
3 changed files with 21 additions and 11 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "langflow"
|
name = "langflow"
|
||||||
version = "0.0.54"
|
version = "0.0.55"
|
||||||
description = "A Python package with a built-in web application"
|
description = "A Python package with a built-in web application"
|
||||||
authors = ["Logspace <contact@logspace.ai>"]
|
authors = ["Logspace <contact@logspace.ai>"]
|
||||||
maintainers = [
|
maintainers = [
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
# - Build each inner agent first, then build the outer agent
|
# - Build each inner agent first, then build the outer agent
|
||||||
|
|
||||||
import types
|
import types
|
||||||
|
import warnings
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
|
|
@ -12,7 +13,6 @@ from langflow.graph.utils import load_file
|
||||||
from langflow.interface import loading
|
from langflow.interface import loading
|
||||||
from langflow.interface.listing import ALL_TYPES_DICT
|
from langflow.interface.listing import ALL_TYPES_DICT
|
||||||
from langflow.utils.logger import logger
|
from langflow.utils.logger import logger
|
||||||
import warnings
|
|
||||||
|
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
|
|
|
||||||
|
|
@ -73,9 +73,14 @@ class ToolCreator(LangChainTypeCreator):
|
||||||
base_classes = ["Tool"]
|
base_classes = ["Tool"]
|
||||||
all_tools = {}
|
all_tools = {}
|
||||||
for tool in self.type_to_loader_dict.keys():
|
for tool in self.type_to_loader_dict.keys():
|
||||||
if tool_params := get_tool_params(get_tool_by_name(tool)):
|
tool_fcn = get_tool_by_name(tool)
|
||||||
|
if tool_params := get_tool_params(tool_fcn):
|
||||||
tool_name = tool_params.get("name") or str(tool)
|
tool_name = tool_params.get("name") or str(tool)
|
||||||
all_tools[tool_name] = {"type": tool, "params": tool_params}
|
all_tools[tool_name] = {
|
||||||
|
"type": tool,
|
||||||
|
"params": tool_params,
|
||||||
|
"fcn": tool_fcn,
|
||||||
|
}
|
||||||
|
|
||||||
# Raise error if name is not in tools
|
# Raise error if name is not in tools
|
||||||
if name not in all_tools.keys():
|
if name not in all_tools.keys():
|
||||||
|
|
@ -83,15 +88,21 @@ class ToolCreator(LangChainTypeCreator):
|
||||||
|
|
||||||
tool_type: str = all_tools[name]["type"] # type: ignore
|
tool_type: str = all_tools[name]["type"] # type: ignore
|
||||||
|
|
||||||
if tool_type in _BASE_TOOLS:
|
if all_tools[tool_type]["fcn"] in _BASE_TOOLS.values():
|
||||||
params = []
|
params = []
|
||||||
elif tool_type in _LLM_TOOLS:
|
elif all_tools[tool_type]["fcn"] in _LLM_TOOLS.values():
|
||||||
params = ["llm"]
|
params = ["llm"]
|
||||||
elif tool_type in _EXTRA_LLM_TOOLS:
|
elif all_tools[tool_type]["fcn"] in [
|
||||||
_, extra_keys = _EXTRA_LLM_TOOLS[tool_type]
|
val[0] for val in _EXTRA_LLM_TOOLS.values()
|
||||||
|
]:
|
||||||
|
n_dict = {val[0]: val[1] for val in _EXTRA_LLM_TOOLS.values()}
|
||||||
|
extra_keys = n_dict[all_tools[tool_type]["fcn"]]
|
||||||
params = ["llm"] + extra_keys
|
params = ["llm"] + extra_keys
|
||||||
elif tool_type in _EXTRA_OPTIONAL_TOOLS:
|
elif all_tools[tool_type]["fcn"] in [
|
||||||
_, extra_keys = _EXTRA_OPTIONAL_TOOLS[tool_type]
|
val[0] for val in _EXTRA_OPTIONAL_TOOLS.values()
|
||||||
|
]:
|
||||||
|
n_dict = {val[0]: val[1] for val in _EXTRA_OPTIONAL_TOOLS.values()} # type: ignore
|
||||||
|
extra_keys = n_dict[all_tools[tool_type]["fcn"]]
|
||||||
params = extra_keys
|
params = extra_keys
|
||||||
elif tool_type == "Tool":
|
elif tool_type == "Tool":
|
||||||
params = ["name", "description", "func"]
|
params = ["name", "description", "func"]
|
||||||
|
|
@ -104,7 +115,6 @@ class ToolCreator(LangChainTypeCreator):
|
||||||
elif tool_type in FILE_TOOLS:
|
elif tool_type in FILE_TOOLS:
|
||||||
params = all_tools[name]["params"] # type: ignore
|
params = all_tools[name]["params"] # type: ignore
|
||||||
base_classes += [name]
|
base_classes += [name]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
params = []
|
params = []
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue