Bases: SerializableMixin
, ABC
Source code in griptape/memory/structure/base_conversation_memory.py
| @define
class BaseConversationMemory(SerializableMixin, ABC):
driver: Optional[BaseConversationMemoryDriver] = field(default=None, kw_only=True)
runs: list[Run] = field(factory=list, kw_only=True, metadata={"serializable": True})
structure: Structure = field(init=False)
autoload: bool = field(default=True, kw_only=True)
autoprune: bool = field(default=True, kw_only=True)
max_runs: Optional[int] = field(default=None, kw_only=True, metadata={"serializable": True})
def __attrs_post_init__(self) -> None:
if self.driver and self.autoload:
memory = self.driver.load()
if memory is not None:
[self.add_run(r) for r in memory.runs]
def before_add_run(self) -> None:
pass
def add_run(self, run: Run) -> BaseConversationMemory:
self.before_add_run()
self.try_add_run(run)
self.after_add_run()
return self
def after_add_run(self) -> None:
if self.driver:
self.driver.store(self)
@abstractmethod
def try_add_run(self, run: Run) -> None:
...
@abstractmethod
def to_prompt_stack(self, last_n: Optional[int] = None) -> PromptStack:
...
|
autoload: bool = field(default=True, kw_only=True)
class-attribute
instance-attribute
autoprune: bool = field(default=True, kw_only=True)
class-attribute
instance-attribute
driver: Optional[BaseConversationMemoryDriver] = field(default=None, kw_only=True)
class-attribute
instance-attribute
max_runs: Optional[int] = field(default=None, kw_only=True, metadata={'serializable': True})
class-attribute
instance-attribute
runs: list[Run] = field(factory=list, kw_only=True, metadata={'serializable': True})
class-attribute
instance-attribute
structure: Structure = field(init=False)
class-attribute
instance-attribute
__attrs_post_init__()
Source code in griptape/memory/structure/base_conversation_memory.py
| def __attrs_post_init__(self) -> None:
if self.driver and self.autoload:
memory = self.driver.load()
if memory is not None:
[self.add_run(r) for r in memory.runs]
|
add_run(run)
Source code in griptape/memory/structure/base_conversation_memory.py
| def add_run(self, run: Run) -> BaseConversationMemory:
self.before_add_run()
self.try_add_run(run)
self.after_add_run()
return self
|
after_add_run()
Source code in griptape/memory/structure/base_conversation_memory.py
| def after_add_run(self) -> None:
if self.driver:
self.driver.store(self)
|
before_add_run()
Source code in griptape/memory/structure/base_conversation_memory.py
| def before_add_run(self) -> None:
pass
|
to_prompt_stack(last_n=None)
abstractmethod
Source code in griptape/memory/structure/base_conversation_memory.py
| @abstractmethod
def to_prompt_stack(self, last_n: Optional[int] = None) -> PromptStack:
...
|
try_add_run(run)
abstractmethod
Source code in griptape/memory/structure/base_conversation_memory.py
| @abstractmethod
def try_add_run(self, run: Run) -> None:
...
|