-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add GriptapeCloudConversationMemoryDriver
#1063
Conversation
Codecov ReportAttention: Patch coverage is 📢 Thoughts on this report? Let us know! |
e381255
to
873c919
Compare
griptape/drivers/memory/conversation/griptape_cloud_conversation_memory_driver.py
Outdated
Show resolved
Hide resolved
griptape/drivers/memory/conversation/griptape_cloud_conversation_memory_driver.py
Outdated
Show resolved
Hide resolved
griptape/drivers/memory/conversation/griptape_cloud_conversation_memory_driver.py
Outdated
Show resolved
Hide resolved
griptape/drivers/memory/conversation/griptape_cloud_conversation_memory_driver.py
Outdated
Show resolved
Hide resolved
griptape/drivers/memory/conversation/griptape_cloud_conversation_memory_driver.py
Outdated
Show resolved
Hide resolved
griptape/drivers/memory/conversation/griptape_cloud_conversation_memory_driver.py
Outdated
Show resolved
Hide resolved
griptape/drivers/memory/conversation/griptape_cloud_conversation_memory_driver.py
Outdated
Show resolved
Hide resolved
griptape/drivers/memory/conversation/griptape_cloud_conversation_memory_driver.py
Outdated
Show resolved
Hide resolved
griptape/drivers/memory/conversation/griptape_cloud_conversation_memory_driver.py
Outdated
Show resolved
Hide resolved
2e9557f
to
819e2c9
Compare
819e2c9
to
805e8f8
Compare
griptape/drivers/memory/conversation/griptape_cloud_conversation_memory_driver.py
Show resolved
Hide resolved
messages = [ | ||
{"input": json.dumps(run.input.to_dict()), "output": json.dumps(run.output.to_dict())} | ||
for run in memory.runs | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be simplified to:
messages = [
{"input": run.input.to_json(), "output": run.output.to_json()}
for run in memory.runs
]
) | ||
response.raise_for_status() | ||
|
||
def load(self) -> Optional[BaseConversationMemory]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be Optional
?
if messages_response is None: | ||
raise RuntimeError(f"Error getting messages for thread {self.thread_id}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When would this happen? Shouldn't raise_for_status
handle this?
griptape/drivers/memory/conversation/griptape_cloud_conversation_memory_driver.py
Show resolved
Hide resolved
# remove runs because they are already stored as Messages | ||
metadata = memory.to_dict() | ||
del metadata["runs"] | ||
metadata = json.dumps(metadata) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More of a comment on Cloud but it seems like metadata
should be a dictionary. What do we gain from it being a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more flexible. it could be used as we do actually care and it is a dict typemetadata="test"
for all we care
{ | ||
**json.loads(thread_response.get("metadata")), | ||
"runs": [run.to_dict() for run in runs], | ||
"autoload": False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For visibility of offline conversation, why is this necessary in this Driver but not others?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you confirm that this is still necessary? Or can you test other Drivers to see if they should have this too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated other drivers with this fix
def get(*args, **kwargs): | ||
if str(args[0]).startswith("https://cloud.griptape.ai/api/threads/"): | ||
if str(args[0]).endswith("/messages"): | ||
thread_id = args[0].split("/")[-2] | ||
if thread_id == "test_error": | ||
return mocker.Mock(raise_for_status=lambda: None, json=lambda: None) | ||
return mocker.Mock( | ||
raise_for_status=lambda: None, | ||
json=lambda: { | ||
"messages": [ | ||
{ | ||
"message_id": "123", | ||
"input": '{"type": "TextArtifact", "id": "1234", "value": "Hi There, Hello"}', | ||
"output": '{"type": "TextArtifact", "id": "123", "value": "Hello! How can I assist you today?"}', | ||
"index": 0, | ||
} | ||
] | ||
}, | ||
) | ||
else: | ||
thread_id = args[0].split("/")[-1] | ||
return mocker.Mock( | ||
raise_for_status=lambda: None, | ||
json=lambda: {"metadata": TEST_CONVERSATION, "name": "test", "thread_id": "test_metadata"} | ||
if thread_id == "test_metadata" | ||
else {"name": "test", "thread_id": "test"}, | ||
) | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to split this over two mocked requests clients.
@pytest.fixture(autouse=True) | ||
def _mock_requests(self, mocker): | ||
def get(*args, **kwargs): | ||
if str(args[0]).startswith("https://cloud.griptape.ai/api/threads/"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When would this ever not evaluate to True
in the context of this test?
55e08d4
to
b59f6e3
Compare
b59f6e3
to
74a08a3
Compare
GriptapeCloudConversationMemoryDriver
Describe your changes
GriptapeCloudConversationMemoryDriver
Issue ticket number and link