Skip to content

Local conversation memory driver

LocalConversationMemoryDriver

Bases: BaseConversationMemoryDriver

Source code in griptape/griptape/drivers/memory/conversation/local_conversation_memory_driver.py
@define
class LocalConversationMemoryDriver(BaseConversationMemoryDriver):
    file_path: str = field(default="griptape_memory.json", kw_only=True)

    def store(self, memory: ConversationMemory) -> None:
        with open(self.file_path, "w") as file:
            file.write(memory.to_json())

    def load(self) -> Optional[ConversationMemory]:
        if not os.path.exists(self.file_path):
            return None
        with open(self.file_path) as file:
            memory = ConversationMemory.from_json(file.read())

            memory.driver = self

            return memory

file_path: str = field(default='griptape_memory.json', kw_only=True) class-attribute instance-attribute

load()

Source code in griptape/griptape/drivers/memory/conversation/local_conversation_memory_driver.py
def load(self) -> Optional[ConversationMemory]:
    if not os.path.exists(self.file_path):
        return None
    with open(self.file_path) as file:
        memory = ConversationMemory.from_json(file.read())

        memory.driver = self

        return memory

store(memory)

Source code in griptape/griptape/drivers/memory/conversation/local_conversation_memory_driver.py
def store(self, memory: ConversationMemory) -> None:
    with open(self.file_path, "w") as file:
        file.write(memory.to_json())