code: def write_alldata(opt, chats, dpath, ltype, split):
      # for now train, valid and test will all be identical
      fname = os.path.join(dpath, ltype + "_" + split + ".txt")
      fw_tst = io.open(fname, "w")
      for chat in chats:
          chat = chat.copy()
          try:
              chat["self_agent"] = {
                  "name": chat["human_persona"]["name"],
                  "persona": chat["human_persona"]["persona"],
              }
              chat["partner_agent"] = {
                  "name": chat["bot_persona"]["name"],
                  "persona": chat["bot_persona"]["persona"],
              }
          except Exception as e:
              print(chat)
              raise (e)
          chat["setting"] = {
              "name": chat["location"]["name"],
              "category": "Somewhere",  # TODO pull from DB?
              "description": chat["location"]["description"],
          }
          turns = chat["dialogue"]
          fin_turns = [t["text"] for t in turns]
          chat["speech"] = [None] + fin_turns
          chat["action"] = [None] * len(chat["speech"])
          chat["emote"] = [None] * len(chat["speech"])
          if opt["light_use_unseen_test"]:
              setting = chat["location"]["name"].lower()
              if setting not in unseen:
                  #   import pdb; pdb.set_trace()
                  write_dialog(opt, fw_tst, chat, ltype, split)
          else:
              write_dialog(opt, fw_tst, chat, ltype, split)
      fw_tst.close()
  
imports: import random
  import io
  import os
  import json
  from parlai.utils.misc import msg_to_str
label_desc: Use image node_id 6 for calling a global function with example usage: write_alldata(opt, chats, dpath, ltype, split) without return types