Spaces:
Sleeping
Sleeping
Update chatbot/memory.py
Browse files- chatbot/memory.py +9 -2
chatbot/memory.py
CHANGED
@@ -1,9 +1,16 @@
|
|
1 |
from langchain.memory import ConversationSummaryBufferMemory
|
2 |
-
from
|
|
|
|
|
|
|
|
|
3 |
|
4 |
memory = ConversationSummaryBufferMemory(
|
5 |
llm=gemini_llm,
|
6 |
memory_key="chat_history", # this key will hold the conversation context
|
|
|
7 |
max_token_limit=2000, # adjust this limit based on your needs
|
8 |
-
|
|
|
|
|
9 |
)
|
|
|
1 |
from langchain.memory import ConversationSummaryBufferMemory
|
2 |
+
from langchain.memory import ChatMessageHistory
|
3 |
+
from langchain.schema import AIMessage, HumanMessage
|
4 |
+
|
5 |
+
# Khởi tạo chat history
|
6 |
+
chat_history = ChatMessageHistory()
|
7 |
|
8 |
memory = ConversationSummaryBufferMemory(
|
9 |
llm=gemini_llm,
|
10 |
memory_key="chat_history", # this key will hold the conversation context
|
11 |
+
input_key="question", # Key input từ người dùng
|
12 |
max_token_limit=2000, # adjust this limit based on your needs
|
13 |
+
prompt=summary_prompt,
|
14 |
+
moving_summary_buffer="summary", # Lưu summary của hội thoại
|
15 |
+
chat_memory=chat_history # Lưu trữ toàn bộ hội thoại (bao gồm cả câu hỏi và phản hồi)
|
16 |
)
|