🔧 fix(customs.py): add MongoDBChatMessageHistory to CUSTOM_NODES dictionary
✨ feat(memories.py): add MongoDBChatMessageHistoryFrontendNode class to support MongoDB as a memory store
The CUSTOM_NODES dictionary in customs.py has been updated to include the "MongoDBChatMessageHistory" memory. This allows the application to use MongoDB as a memory store for chat message history. The MongoDBChatMessageHistoryFrontendNode class has been added to memories.py, providing the necessary functionality and configuration options for interacting with MongoDB as a memory store.
This commit is contained in:
parent
05f30a585f
commit
fc4dca8a6d
2 changed files with 58 additions and 0 deletions
|
|
@ -23,6 +23,7 @@ CUSTOM_NODES = {
|
|||
},
|
||||
"memories": {
|
||||
"PostgresChatMessageHistory": frontend_node.memories.PostgresChatMessageHistoryFrontendNode(),
|
||||
"MongoDBChatMessageHistory": frontend_node.memories.MongoDBChatMessageHistoryFrontendNode(),
|
||||
},
|
||||
"chains": {
|
||||
"SeriesCharacterChain": frontend_node.chains.SeriesCharacterChainNode(),
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue