Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Save conversations check for parent directory #4218

Merged
merged 5 commits into from
Dec 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions parlai/utils/conversations.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ def _get_path(datapath):
fle, _ = os.path.splitext(datapath)
return fle + '.jsonl'

@staticmethod
def _check_parent_dir_exits(datapath):
parent_dir = os.path.dirname(datapath)
if not parent_dir or PathManager.exists(parent_dir):
return
logging.info(f'Parent directory ({parent_dir}) did not exist and was created.')
PathManager.mkdirs(parent_dir)

@classmethod
def save_conversations(
cls,
Expand All @@ -294,6 +302,7 @@ def save_conversations(
each of which is comprised of a list of act pairs (i.e. a list dictionaries
returned from one parley)
"""
cls._check_parent_dir_exits(datapath)
to_save = cls._get_path(datapath)

context_ids = context_ids.strip().split(',')
Expand Down