How to read memory messages from specific session id? #3419
Replies: 2 comments 1 reply
-
To read memory messages from a specific session ID in your memory chatbot project, you need to ensure that the Here is a relevant code snippet from the class MemoryComponent(Component):
# ... other parts of the class ...
def retrieve_messages(self) -> Data:
sender = self.sender
sender_name = self.sender_name
session_id = self.session_id
n_messages = self.n_messages
order = "DESC" if self.order == "Descending" else "ASC"
if sender == "Machine and User":
sender = None
messages = get_messages(
sender=sender,
sender_name=sender_name,
session_id=session_id,
limit=n_messages,
order=order,
)
self.status = messages
return messages
def retrieve_messages_as_text(self) -> Message:
messages_text = data_to_text(self.template, self.retrieve_messages())
self.status = messages_text
return Message(text=messages_text) Ensure that the "ChatInput-baxPA": {
"files": "",
"sender": "User",
"sender_name": "User",
"session_id": sessionID
},
"ChatOutput-8U3qC": {
"data_template": "{text}",
"sender": "Machine",
"sender_name": "AI",
"session_id": sessionID
},
"MemoryComponent": {
"session_id": sessionID,
# other configurations...
} The def get_messages(
sender: Optional[str] = None,
sender_name: Optional[str] = None,
session_id: Optional[str] = None,
order_by: Optional[str] = "timestamp",
order: Optional[str] = "DESC",
limit: Optional[int] = None,
):
monitor_service = get_monitor_service()
messages_df = monitor_service.get_messages(
sender=sender,
sender_name=sender_name,
session_id=session_id,
order_by=order_by,
limit=limit,
order=order,
)
records: list[Record] = []
messages_df = messages_df[::-1] if order == "DESC" else messages_df
for row in messages_df.itertuples():
record = Record(
data={
"text": row.message,
"sender": row.sender,
"sender_name": row.sender_name,
"session_id": row.session_id,
},
)
records.append(record)
return records Make sure that the |
Beta Was this translation helpful? Give feedback.
-
@dosu
|
Beta Was this translation helpful? Give feedback.
-
Hi, I made a memory chatbot project and found although I already write session id in GroupNode-3m6Jg component, it will still resd messages from every session.
Beta Was this translation helpful? Give feedback.
All reactions