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) )