class_docstr: Interactive world for wizard of wikipedia.
  
  Used for models trained on the task `-t wizard_of_wikipedia`. Automatically
  retrieves knowledge from Wikipedia based on the conversation history using a TF-IDF
  retriever. Then uses a Transformer-based model to select a checked sentence from
  these retrieved passages.
class_docstr_tok: ["Interactive","world","for","wizard","of","wikipedia",".","Used","for","models","trained","on","the","task","`","-t","wizard_of_wikipedia","`",".","Automatically","retrieves","knowledge","from","Wikipedia","based","on","the","conversation","history","using","a","TF-IDF","retriever",".","Then","uses","a","Transformer-based","model","to","select","a","checked","sentence","from","these","retrieved","passages","."]
docstr: Loop between wizard and apprentice.
  
  Adds knowledge to the wizard observations. Assumes that the model agent is the
  wizard model.
docstr_tok: ["Loop","between","wizard","and","apprentice",".","Adds","knowledge","to","the","wizard","observations",".","Assumes","that","the","model","agent","is","the","wizard","model","."]
code: def parley(self):
      """
      Loop between wizard and apprentice.
  
      Adds knowledge to the wizard observations. Assumes that the model agent is the
      wizard model.
      """
  
      if self.cnt == 0:
          self.topic = self._get_new_topic()
          self.acts = [None, None]
          if self.topic != NO_TOPIC:
              self.human_first = random.choice([0, 1])
          else:
              self.human_first = 1
  
      # possibly get human act first
      if self.cnt == 0 and not self.human_first:
          self.acts[0] = act = Message(
              {"text": "", "episode_done": False}
          )
          act = self.acts[0]
      else:
          self.acts[0] = self.human_agent.act()
          act = deepcopy(self.acts[0])
  
      # model agent observe
      if self.cnt == 0 and self.topic != NO_TOPIC:
          # add the chosen_topic to the message
          act["chosen_topic"] = self.topic
          act.force_set(
              "text", "\n".join([self.topic, act.get("text", "hi")])
          )
  
      # add knowledge to the model observation
      act = self._add_knowledge_to_act(act)
  
      # model observes knowledge and human (apprentice) act
      self.model_agent.observe(validate(act))
  
      # model agent act
      self.acts[1] = self.model_agent.act()
  
      # add the model reply to the knowledge retriever's dialogue history
      self.knowledge_agent.observe(self.acts[1], actor_id="wizard")
  
      # human (apprentice) agent observes model act
      self.human_agent.observe(validate(self.acts[1]))
  
      self.update_counters()
      self.cnt += 1
  
      if self.episode_done():
          print("[ CHAT DONE ]")
          print("\n[ Preparing new chat... ]\n")
          self.cnt = 0
          self.model_agent.reset()
  
imports: from typing import Optional
  from parlai.core.opt import Opt
  from copy import deepcopy
  import json
  import random
  import os
  import string
  from parlai.core.params import ParlaiParser
  from parlai.core.agents import create_agent
  from parlai.core.message import Message
  from parlai.core.worlds import DialogPartnerWorld, validate
  from parlai.tasks.wizard_of_wikipedia.agents import TOKEN_KNOWLEDGE, TOKEN_END_KNOWLEDGE
  from parlai.tasks.self_chat.worlds import SelfChatWorld
  from parlai.utils.misc import warn_once
  from .build import build
  from projects.wizard_of_wikipedia.knowledge_retriever.knowledge_retriever import KnowledgeRetrieverAgent
label_desc: Use image node_id 7 for calling the InteractiveWorld obj's underlying member method code with example usage: obj.parley() without return types