code: def self_chat(opt):
      random.seed(opt["seed"])
      partner = opt["partner_model_file"]
      partner_opt_file = opt.get("partner_opt_file")
  
      # Create agents
      agent1 = create_agent(opt, requireModelExists=True)
      agent1.opt.log("Agent 1 Opt")
      if partner is None:
          # Self chat with same model
          agent2 = agent1.clone()
      else:
          # Self chat with different models
          if partner_opt_file:
              print(
                  f"WARNING: Loading override opts from: {partner_opt_file}"
              )
              with PathManager.open(partner_opt_file) as f:
                  partner_opt = json.load(f)
          else:
              partner_opt = {}
          partner_opt["interactive_mode"] = opt.get(
              "interactive_mode", True
          )
          print(
              f"WARNING: Setting partner interactive mode to: {partner_opt['interactive_mode']}"
          )
          agent2 = create_agent_from_model_file(partner, partner_opt)
          agent2.opt.log("Agent 2 Opt")
  
      # Set IDs
      agent1.id = agent1.id + "_1"
      agent2.id = agent2.id + "_2"
  
      model_id = agent1.id + "_" + agent2.id
  
      world = create_task(opt, user_agents=[agent1, agent2])
  
      # Set up world logging
      logger = WorldLogger(opt)
      log_time = TimeLogger()
  
      # Run some self chats.
      for i in range(opt["num_self_chats"]):
          _run_self_chat_episode(opt, world, logger)
          report = world.report()
          text, report = log_time.log(
              i + 1, opt["num_self_chats"], report
          )
          logging.info(text)
  
      # Save chats
      if opt["outfile"] is None:
          outfile = "/tmp/{}_selfchat".format(model_id)
      else:
          outfile = opt["outfile"]
  
      if opt["save_format"] == "conversations" and hasattr(
          world, "write"
      ):
          # use self chat specific world to write conversation
          # this might be useful for logging extra contextual
          # information (like personas)
          world.write(logger, outfile)
      else:
          # use default logger write function
          logger.write(outfile, world, opt["save_format"])
  
      return logger.get_logs()
  
file_path: ParlAI/parlai/scripts/self_chat.py
imports: from parlai.core.params import ParlaiParser
  from parlai.core.agents import create_agent, create_agent_from_model_file
  from parlai.core.worlds import create_task
  from parlai.utils.world_logging import WorldLogger
  from parlai.utils.misc import TimeLogger
  from parlai.core.script import ParlaiScript, register_script
  import parlai.utils.logging
  from parlai.utils.io import PathManager
  import math
  import json
  import random
label_desc: Use image node_id 3 for calling a global function with example usage: self_chat(opt) and returns: logger