Spaces:
Sleeping
Sleeping
File size: 794 Bytes
dedac20 98e4789 e1f6f95 8954fe5 98e4789 ed3a456 dedac20 98e4789 dedac20 98e4789 dedac20 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
from langchain.memory import ConversationSummaryBufferMemory
from langchain.memory import ChatMessageHistory
from langchain.schema import AIMessage, HumanMessage
from chatbot.llm import gemini_llm
from chatbot.prompts import summary_prompt
# Khởi tạo chat history
chat_history = ChatMessageHistory()
memory = ConversationSummaryBufferMemory(
llm=gemini_llm,
memory_key="chat_history", # this key will hold the conversation context
input_key="question", # Key input từ người dùng
max_token_limit=2000, # adjust this limit based on your needs
prompt=summary_prompt,
moving_summary_buffer="summary", # Lưu summary của hội thoại
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)
)
|