Skip to content

Commit

Permalink
Refactor to make FileConversationStore more extendable (#5922)
Browse files Browse the repository at this point in the history
  • Loading branch information
tofarr authored Dec 30, 2024
1 parent bb578a2 commit d7a3ec6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions openhands/storage/conversation/file_conversation_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,25 @@ class FileConversationStore(ConversationStore):

async def save_metadata(self, metadata: ConversationMetadata):
json_str = json.dumps(metadata.__dict__)
path = get_conversation_metadata_filename(metadata.conversation_id)
path = self.get_conversation_metadata_filename(metadata.conversation_id)
await call_sync_from_async(self.file_store.write, path, json_str)

async def get_metadata(self, conversation_id: str) -> ConversationMetadata:
path = get_conversation_metadata_filename(conversation_id)
path = self.get_conversation_metadata_filename(conversation_id)
json_str = await call_sync_from_async(self.file_store.read, path)
return ConversationMetadata(**json.loads(json_str))

async def exists(self, conversation_id: str) -> bool:
path = get_conversation_metadata_filename(conversation_id)
path = self.get_conversation_metadata_filename(conversation_id)
try:
await call_sync_from_async(self.file_store.read, path)
return True
except FileNotFoundError:
return False

def get_conversation_metadata_filename(self, conversation_id: str) -> str:
return get_conversation_metadata_filename(conversation_id)

@classmethod
async def get_instance(cls, config: AppConfig, token: str | None):
file_store = get_file_store(config.file_store, config.file_store_path)
Expand Down

0 comments on commit d7a3ec6

Please sign in to comment.