From 487d4aeebda1410112015d8ee0adcf229b59a7d5 Mon Sep 17 00:00:00 2001 From: Bank Natchapol Date: Tue, 2 May 2023 07:02:34 +0700 Subject: [PATCH] Motorhead Memory messages come in reversed order. (#3835) History from Motorhead memory return in reversed order It should be Human: 1, AI:..., Human: 2, Ai... ``` You are a chatbot having a conversation with a human. AI: I'm sorry, I'm still not sure what you're trying to communicate. Can you please provide more context or information? Human: 3 AI: I'm sorry, I'm not sure what you mean by "1" and "2". Could you please clarify your request or question? Human: 2 AI: Hello, how can I assist you today? Human: 1 Human: 4 AI: ``` So, i `reversed` the messages before putting in chat_memory. --- langchain/memory/motorhead_memory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/langchain/memory/motorhead_memory.py b/langchain/memory/motorhead_memory.py index 393db8b854c..3f5bb3002cb 100644 --- a/langchain/memory/motorhead_memory.py +++ b/langchain/memory/motorhead_memory.py @@ -23,7 +23,7 @@ class MotorheadMemory(BaseChatMemory): messages = res_data.get("messages", []) context = res_data.get("context", "NONE") - for message in messages: + for message in reversed(messages): if message["role"] == "AI": self.chat_memory.add_ai_message(message["content"]) else: