From fc4dca8a6d6fee1158c04b9e4c253df1871631b5 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 7 Jul 2023 17:48:37 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix(customs.py):=20add=20MongoDB?= =?UTF-8?q?ChatMessageHistory=20to=20CUSTOM=5FNODES=20dictionary=20?= =?UTF-8?q?=E2=9C=A8=20feat(memories.py):=20add=20MongoDBChatMessageHistor?= =?UTF-8?q?yFrontendNode=20class=20to=20support=20MongoDB=20as=20a=20memor?= =?UTF-8?q?y=20store=20The=20CUSTOM=5FNODES=20dictionary=20in=20customs.py?= =?UTF-8?q?=20has=20been=20updated=20to=20include=20the=20"MongoDBChatMess?= =?UTF-8?q?ageHistory"=20memory.=20This=20allows=20the=20application=20to?= =?UTF-8?q?=20use=20MongoDB=20as=20a=20memory=20store=20for=20chat=20messa?= =?UTF-8?q?ge=20history.=20The=20MongoDBChatMessageHistoryFrontendNode=20c?= =?UTF-8?q?lass=20has=20been=20added=20to=20memories.py,=20providing=20the?= =?UTF-8?q?=20necessary=20functionality=20and=20configuration=20options=20?= =?UTF-8?q?for=20interacting=20with=20MongoDB=20as=20a=20memory=20store.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/custom/customs.py | 1 + .../template/frontend_node/memories.py | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/backend/langflow/custom/customs.py b/src/backend/langflow/custom/customs.py index bbafb4526..58ef1b508 100644 --- a/src/backend/langflow/custom/customs.py +++ b/src/backend/langflow/custom/customs.py @@ -23,6 +23,7 @@ CUSTOM_NODES = { }, "memories": { "PostgresChatMessageHistory": frontend_node.memories.PostgresChatMessageHistoryFrontendNode(), + "MongoDBChatMessageHistory": frontend_node.memories.MongoDBChatMessageHistoryFrontendNode(), }, "chains": { "SeriesCharacterChain": frontend_node.chains.SeriesCharacterChainNode(), diff --git a/src/backend/langflow/template/frontend_node/memories.py b/src/backend/langflow/template/frontend_node/memories.py index 6d490212f..d98a322ff 100644 --- a/src/backend/langflow/template/frontend_node/memories.py +++ b/src/backend/langflow/template/frontend_node/memories.py @@ -4,6 +4,10 @@ from langflow.template.field.base import TemplateField from langflow.template.frontend_node.base import FrontendNode from langflow.template.template.base import Template from langchain.memory.chat_message_histories.postgres import DEFAULT_CONNECTION_STRING +from langchain.memory.chat_message_histories.mongodb import ( + DEFAULT_COLLECTION_NAME, + DEFAULT_DBNAME, +) class MemoryFrontendNode(FrontendNode): @@ -120,3 +124,56 @@ class PostgresChatMessageHistoryFrontendNode(MemoryFrontendNode): ) description: str = "Memory store with Postgres" base_classes: list[str] = ["PostgresChatMessageHistory", "BaseChatMessageHistory"] + + +class MongoDBChatMessageHistoryFrontendNode(MemoryFrontendNode): + name: str = "MongoDBChatMessageHistory" + template: Template = Template( + # langchain/memory/chat_message_histories/mongodb.py + # connection_string: str, + # session_id: str, + # database_name: str = DEFAULT_DBNAME, + # collection_name: str = DEFAULT_COLLECTION_NAME, + type_name="MongoDBChatMessageHistory", + fields=[ + TemplateField( + field_type="str", + required=True, + placeholder="", + is_list=False, + show=True, + multiline=False, + name="session_id", + ), + TemplateField( + field_type="str", + required=True, + show=True, + name="connection_string", + value="", + info="MongoDB connection string (e.g mongodb://mongo_user:password123@mongo:27017)", + ), + TemplateField( + field_type="str", + required=True, + placeholder="", + is_list=False, + show=True, + multiline=False, + value=DEFAULT_DBNAME, + name="database_name", + ), + TemplateField( + field_type="str", + required=True, + placeholder="", + is_list=False, + show=True, + multiline=False, + value=DEFAULT_COLLECTION_NAME, + name="collection_name", + ), + ], + ) + description: str = "Memory store with MongoDB" + base_classes: list[str] = ["MongoDBChatMessageHistory", "BaseChatMessageHistory"]