🐛 fix(base.py): extend list only if key exists and is a list

🐛 fix(nodes.py): flatten list of tools if it is a list of lists
🐛 fix(toolkits/base.py): add "toolkit" check to avoid adding "Tool" to non-toolkit classes
📝 docs(agents.py): update node descriptions to reflect CSV and zero shot agents
The changes in base.py and nodes.py ensure that the code works as intended and avoids errors when extending lists. The change in toolkits/base.py ensures that "Tool" is only added to classes that are toolkits. The changes in agents.py update the node descriptions to reflect that the CSVAgentNode constructs a CSV agent and the InitializeAgentNode constructs a zero shot agent.
This commit is contained in:
Gabriel Almeida 2023-05-30 01:11:27 -03:00
commit ad3bb997ee
4 changed files with 14 additions and 3 deletions

View file

@ -175,6 +175,12 @@ class Node:
# turn result which is a function into a coroutine
# so that it can be awaited
self.params["coroutine"] = sync_to_async(result)
if isinstance(result, list):
# If the result is a list, then we need to extend the list
# with the result but first check if the key exists
# if it doesn't, then we need to create a new list
if isinstance(self.params[key], list):
self.params[key].extend(result)
self.params[key] = result
elif isinstance(value, list) and all(

View file

@ -62,6 +62,11 @@ class PromptNode(Node):
if tools is not None
else []
)
# flatten the list of tools if it is a list of lists
# first check if it is a list
if isinstance(tools, list) and isinstance(tools[0], list):
tools = [tool for sublist in tools for tool in sublist]
self.params["tools"] = tools
prompt_params = [
key

View file

@ -44,7 +44,7 @@ class ToolkitCreator(LangChainTypeCreator):
try:
template = build_template_from_class(name, self.type_to_loader_dict)
# add Tool to base_classes
if template:
if "toolkit" in name.lower() and template:
template["base_classes"].append("Tool")
return template
except ValueError as exc:

View file

@ -146,7 +146,7 @@ class CSVAgentNode(FrontendNode):
),
],
)
description: str = """Construct a json agent from a CSV and tools."""
description: str = """Construct a CSV agent from a CSV and tools."""
base_classes: list[str] = ["AgentExecutor"]
def to_dict(self):
@ -194,7 +194,7 @@ class InitializeAgentNode(FrontendNode):
),
],
)
description: str = """Construct a json agent from an LLM and tools."""
description: str = """Construct a zero shot agent from an LLM and tools."""
base_classes: list[str] = ["AgentExecutor", "function"]
def to_dict(self):