talk2data / memory_store.py
amirkiarafiei's picture
refactor: update README for clarity and remove deprecated chat history file
938a3f9
raw
history blame
859 Bytes
from langchain_community.chat_message_histories import ChatMessageHistory
from typing import Optional
import logging
logger = logging.getLogger(__name__)
class MemoryStore:
_instance: Optional['MemoryStore'] = None
_memory: Optional[ChatMessageHistory] = None
def __new__(cls):
if cls._instance is None:
cls._instance = super(MemoryStore, cls).__new__(cls)
cls._memory = ChatMessageHistory()
logger.info("New MemoryStore instance created")
return cls._instance
@classmethod
def get_memory(cls) -> ChatMessageHistory:
if cls._instance is None:
cls._instance = cls()
return cls._memory
@classmethod
def clear_memory(cls):
if cls._memory is not None:
cls._memory = ChatMessageHistory()
logger.info("Memory cleared")