🐛 fix(base.py): add support for creating MemoryFrontendNode from a method

 feat(base.py): add support for creating MemoryFrontendNode from a specific method in ZepChatMessageHistory class
The `MemoryCreator` class now supports creating `MemoryFrontendNode` from a specific method in the `ZepChatMessageHistory` class. This is achieved by adding the `from_method_nodes` dictionary with the method name as the key and the class name as the value. The `build_template_from_method` function is used to create the `MemoryFrontendNode` from the specified method. This enhancement allows for more flexibility in creating `MemoryFrontendNode` instances.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-29 17:39:46 -03:00
commit 7eeacfbb31

View file

@ -6,13 +6,15 @@ from langflow.settings import settings
from langflow.template.frontend_node.base import FrontendNode
from langflow.template.frontend_node.memories import MemoryFrontendNode
from langflow.utils.logger import logger
from langflow.utils.util import build_template_from_class
from langflow.utils.util import build_template_from_class, build_template_from_method
from langflow.custom.customs import get_custom_nodes
class MemoryCreator(LangChainTypeCreator):
type_name: str = "memories"
from_method_nodes = {"ZepChatMessageHistory": "__init__"}
@property
def frontend_node_class(self) -> Type[FrontendNode]:
"""The class type of the FrontendNode created in frontend_node."""
@ -29,6 +31,12 @@ class MemoryCreator(LangChainTypeCreator):
try:
if name in get_custom_nodes(self.type_name).keys():
return get_custom_nodes(self.type_name)[name]
elif name in self.from_method_nodes:
return build_template_from_method(
name,
type_to_cls_dict=memory_type_to_cls_dict,
method_name=self.from_method_nodes[name],
)
return build_template_from_class(name, memory_type_to_cls_dict)
except ValueError as exc:
raise ValueError("Memory not found") from exc