From ad3bb997eed981c9426e0b76b16f84309b18ae74 Mon Sep 17 00:00:00 2001 From: Gabriel Almeida Date: Tue, 30 May 2023 01:11:27 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(base.py):=20extend=20list=20?= =?UTF-8?q?only=20if=20key=20exists=20and=20is=20a=20list=20=F0=9F=90=9B?= =?UTF-8?q?=20fix(nodes.py):=20flatten=20list=20of=20tools=20if=20it=20is?= =?UTF-8?q?=20a=20list=20of=20lists=20=F0=9F=90=9B=20fix(toolkits/base.py)?= =?UTF-8?q?:=20add=20"toolkit"=20check=20to=20avoid=20adding=20"Tool"=20to?= =?UTF-8?q?=20non-toolkit=20classes=20=F0=9F=93=9D=20docs(agents.py):=20up?= =?UTF-8?q?date=20node=20descriptions=20to=20reflect=20CSV=20and=20zero=20?= =?UTF-8?q?shot=20agents=20The=20changes=20in=20base.py=20and=20nodes.py?= =?UTF-8?q?=20ensure=20that=20the=20code=20works=20as=20intended=20and=20a?= =?UTF-8?q?voids=20errors=20when=20extending=20lists.=20The=20change=20in?= =?UTF-8?q?=20toolkits/base.py=20ensures=20that=20"Tool"=20is=20only=20add?= =?UTF-8?q?ed=20to=20classes=20that=20are=20toolkits.=20The=20changes=20in?= =?UTF-8?q?=20agents.py=20update=20the=20node=20descriptions=20to=20reflec?= =?UTF-8?q?t=20that=20the=20CSVAgentNode=20constructs=20a=20CSV=20agent=20?= =?UTF-8?q?and=20the=20InitializeAgentNode=20constructs=20a=20zero=20shot?= =?UTF-8?q?=20agent.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/graph/base.py | 6 ++++++ src/backend/langflow/graph/nodes.py | 5 +++++ src/backend/langflow/interface/toolkits/base.py | 2 +- src/backend/langflow/template/frontend_node/agents.py | 4 ++-- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/backend/langflow/graph/base.py b/src/backend/langflow/graph/base.py index 5b64885fb..08b255441 100644 --- a/src/backend/langflow/graph/base.py +++ b/src/backend/langflow/graph/base.py @@ -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( diff --git a/src/backend/langflow/graph/nodes.py b/src/backend/langflow/graph/nodes.py index 7d9b05366..ea94e10b8 100644 --- a/src/backend/langflow/graph/nodes.py +++ b/src/backend/langflow/graph/nodes.py @@ -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 diff --git a/src/backend/langflow/interface/toolkits/base.py b/src/backend/langflow/interface/toolkits/base.py index 9f01b2bb2..be2345c02 100644 --- a/src/backend/langflow/interface/toolkits/base.py +++ b/src/backend/langflow/interface/toolkits/base.py @@ -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: diff --git a/src/backend/langflow/template/frontend_node/agents.py b/src/backend/langflow/template/frontend_node/agents.py index e4fe40187..451dd7eca 100644 --- a/src/backend/langflow/template/frontend_node/agents.py +++ b/src/backend/langflow/template/frontend_node/agents.py @@ -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):