class_docstr: Utility class for reading and writing from ParlAI Conversations format.
  
  Conversations should be saved in JSONL format, where each line is
  a JSON of the following form:
  
  WARNING: The data below must be on ONE LINE per dialogue
  in a conversation file or it will not load!!
  
  .. code-block:
  
      {
          'possible_conversation_level_info': True,
          'dialog':
              [   [
                      {
                          'id': 'speaker_1',
                          'text': <first utterance>,
                      },
                      {
                          'id': 'speaker_2',
                          'text': <second utterance>,
                      },
                      ...
                  ],
                  ...
              ]
          ...
      }
class_docstr_tok: ["Utility","class","for","reading","and","writing","from","ParlAI","Conversations","format",".","Conversations","should","be","saved","in","JSONL","format",",","where","each","line","is","a","JSON","of","the","following","form",":","WARNING",":","The","data","below","must","be","on","ONE","LINE","per","dialogue","in","a","conversation","file","or","it","will","not","load","!","!","..","code-block",":","{","'possible_conversation_level_info","'",":","True",",","'dialog","'",":","[","[","{","'id","'",":","'speaker_1","'",",","'text","'",":","<","first","utterance",">",",","}",",","{","'id","'",":","'speaker_2","'",",","'text","'",":","<","second","utterance",">",",","}",",","...","]",",","...","]","...","}"]
docstr: Write Conversations to file from an act list.
  
  Conversations assume the act list is of the following form: a list of episodes,
  each of which is comprised of a list of act pairs (i.e. a list dictionaries
  returned from one parley)
docstr_tok: ["Write","Conversations","to","file","from","an","act","list",".","Conversations","assume","the","act","list","is","of","the","following","form",":","a","list","of","episodes",",","each","of","which","is","comprised","of","a","list","of","act","pairs","(","i.e",".","a","list","dictionaries","returned","from","one","parley",")"]
code: def save_conversations(
      cls,
      act_list,
      datapath,
      opt,
      save_keys="all",
      context_ids="context",
      self_chat=False,
      **kwargs,
  ):
      """
      Write Conversations to file from an act list.
  
      Conversations assume the act list is of the following form: a list of episodes,
      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(",")
      # save conversations
      speakers = []
      with PathManager.open(to_save, "w") as f:
          for ep in act_list:
              if not ep:
                  continue
              convo = {
                  "dialog": [],
                  "context": [],
                  "metadata_path": Metadata._get_path(to_save),
              }
              for act_pair in ep:
                  new_pair = []
                  for ex in act_pair:
                      ex_id = ex.get("id")
                      if ex_id in context_ids:
                          context = True
                      else:
                          context = False
                          if ex_id not in speakers:
                              speakers.append(ex_id)
  
                      # set turn
                      turn = {}
                      if save_keys != "all":
                          save_keys_lst = save_keys.split(",")
                      else:
                          save_keys_lst = ex.keys()
                      for key in save_keys_lst:
                          turn[key] = ex.get(key, "")
                          if key == "metrics":
                              turn[key] = dict_report(turn[key])
                      turn["id"] = ex_id
                      if not context:
                          new_pair.append(turn)
                      else:
                          convo["context"].append(turn)
                  if new_pair:
                      convo["dialog"].append(new_pair)
              json_convo = json.dumps(
                  convo, default=lambda v: "<not serializable>"
              )
              f.write(json_convo + "\n")
      logging.info(f"Conversations saved to file: {to_save}")
  
      # save metadata
      Metadata.save_metadata(
          to_save, opt, self_chat=self_chat, speakers=speakers, **kwargs
      )
  
imports: import datetime
  import json
  import os
  import itertools
  from parlai.utils.io import PathManager
  from parlai.core.metrics import dict_report
  from parlai.utils.misc import AttrDict
  import parlai.utils.logging
label_desc: Use image node_id 12 for calling the Conversations obj's underlying member method code with example usage: obj.save_conversations(cls, act_list, datapath, opt, save_keys, context_ids, _chat) without return types