-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Conversation Memory class and drivers (#1084)
- Loading branch information
Showing
30 changed files
with
322 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 12 additions & 4 deletions
16
griptape/drivers/memory/conversation/base_conversation_memory_driver.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
from __future__ import annotations | ||
|
||
from abc import ABC, abstractmethod | ||
from typing import TYPE_CHECKING, Optional | ||
from typing import TYPE_CHECKING, Any | ||
|
||
from griptape.mixins import SerializableMixin | ||
|
||
if TYPE_CHECKING: | ||
from griptape.memory.structure import BaseConversationMemory | ||
from griptape.memory.structure import Run | ||
|
||
|
||
class BaseConversationMemoryDriver(SerializableMixin, ABC): | ||
@abstractmethod | ||
def store(self, memory: BaseConversationMemory) -> None: ... | ||
def store(self, runs: list[Run], metadata: dict[str, Any]) -> None: ... | ||
|
||
@abstractmethod | ||
def load(self) -> Optional[BaseConversationMemory]: ... | ||
def load(self) -> tuple[list[Run], dict[str, Any]]: ... | ||
|
||
def _to_params_dict(self, runs: list[Run], metadata: dict[str, Any]) -> dict: | ||
return {"runs": [run.to_dict() for run in runs], "metadata": metadata} | ||
|
||
def _from_params_dict(self, params_dict: dict[str, Any]) -> tuple[list[Run], dict[str, Any]]: | ||
from griptape.memory.structure import Run | ||
|
||
return [Run.from_dict(run) for run in params_dict.get("runs", [])], params_dict.get("metadata", {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.