From 659491f9a24919dc2d6310a110a1529f55064d97 Mon Sep 17 00:00:00 2001 From: Gabriel Almeida Date: Fri, 28 Apr 2023 23:30:12 -0300 Subject: [PATCH] feat(langflow): add function support to build_template_from_class function feat(langflow): add function base class to InitializeAgentNode The `build_template_from_class` function in `ChainCreator` now supports adding a function to the chain. This is done by passing `add_function=True` to the function. In `InitializeAgentNode`, the `base_classes` attribute has been updated to include the `function` base class. This allows the node to be used as a function in the chain. --- src/backend/langflow/interface/chains/base.py | 4 +++- src/backend/langflow/template/nodes.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/interface/chains/base.py b/src/backend/langflow/interface/chains/base.py index 9dc8ded3f..7b8da370b 100644 --- a/src/backend/langflow/interface/chains/base.py +++ b/src/backend/langflow/interface/chains/base.py @@ -37,7 +37,9 @@ class ChainCreator(LangChainTypeCreator): try: if name in get_custom_nodes(self.type_name).keys(): return get_custom_nodes(self.type_name)[name] - return build_template_from_class(name, self.type_to_loader_dict) + return build_template_from_class( + name, self.type_to_loader_dict, add_function=True + ) except ValueError as exc: raise ValueError("Chain not found") from exc except AttributeError as exc: diff --git a/src/backend/langflow/template/nodes.py b/src/backend/langflow/template/nodes.py index f0f2112a6..32dbec48a 100644 --- a/src/backend/langflow/template/nodes.py +++ b/src/backend/langflow/template/nodes.py @@ -216,7 +216,7 @@ class InitializeAgentNode(FrontendNode): ], ) description: str = """Construct a json agent from an LLM and tools.""" - base_classes: list[str] = ["AgentExecutor"] + base_classes: list[str] = ["AgentExecutor", "function"] def to_dict(self): return super().to_dict()