class_docstr: Base Teacher that extract metadata for dialogues.
class_docstr_tok: ["Base","Teacher","that","extract","metadata","for","dialogues","."]
code: def _add_feedback_to_perfect_utt(
      self, bot_acts, human_acts, perfect_dialog_context
  ):
      feedback_chain = [
          bot_act.get("improve_bucket", FeedbackType.PERFECT.value)
          for bot_act in bot_acts
      ]
      feedback_examples = []
      effective_human_feedback = {}
      human_revision = {"search_query": [], "selected_sentences": []}
      bot_gold = {"search_query": []}
      bot_no_feedback = {"search_query": []}
      bot_modular_failure = {"search_query": []}
      woi_format_gold_docs = {
          woi_consts.SELECTED_SENTENCES: []
      }  # otherwise get_retrieved_knowledge will break
      if "search_queries" in bot_acts[0]:
          woi_format_gold_docs = format_to_woi_consistent(
              bot_acts[0]["top_docs"], woi_format_gold_docs
          )
  
      if len(bot_acts) == 1:
          # no feedback turn
          if "search_queries" in bot_acts[0]:
              bot_no_feedback["search_query"].append(
                  bot_acts[0]["search_queries"]
              )
      else:
          for i, bot_act in enumerate(bot_acts):
              # skip updating the top_docs or search_queries if the bot response is from human better_response
              if (
                  i > 0
                  and bot_acts[i - 1].get("improve_bucket", "")
                  != FeedbackType.CORRECT_RESPONSE.value
                  and "top_docs" in bot_act
                  and isinstance(bot_act["top_docs"], list)
              ):
                  woi_format_gold_docs = format_to_woi_consistent(
                      bot_act["top_docs"], woi_format_gold_docs
                  )
              # clear the knowledge sentence selection if it's from a fresh search
              if i > 0 and bot_acts[i - 1].get(
                  "improve_bucket", ""
              ) in [FeedbackType.CORRECT_SEARCH_QUERY.value]:
                  woi_format_gold_docs[
                      woi_consts.SELECTED_SENTENCES
                  ] = []
  
              if (
                  bot_act.get("improve_bucket", "")
                  == FeedbackType.CORRECT_SEARCH_QUERY.value
              ):
                  effective_human_feedback = {
                      "search_query": bot_acts[i + 1]["search_queries"]
                  }
                  human_revision["search_query"].append(
                      effective_human_feedback["search_query"]
                  )
                  if "search_queries" in bot_act:
                      bot_modular_failure["search_query"].append(
                          bot_act["search_queries"]
                      )
              elif (
                  bot_act.get("improve_bucket", "")
                  == FeedbackType.CORRECT_DOC.value
              ):
                  if "better_response" in effective_human_feedback:
                      del effective_human_feedback["better_response"]
                  effective_human_feedback[
                      "selected_sentences"
                  ] = human_acts[i + 1]["feedback_text"]
                  human_revision["selected_sentences"].append(
                      effective_human_feedback["selected_sentences"]
                  )
                  woi_format_gold_docs[
                      woi_consts.SELECTED_SENTENCES
                  ] = [effective_human_feedback["selected_sentences"]]
                  bot_gold["search_query"].append(
                      bot_acts[i]["search_queries"]
                  )
              elif (
                  bot_act.get("improve_bucket", "")
                  == FeedbackType.CORRECT_RESPONSE.value
              ):
                  effective_human_feedback[
                      "better_response"
                  ] = human_acts[i + 1]["feedback_text"]
  
              # collect feedback examples as target
              if bot_act.get("improve_bucket", "") in [
                  FeedbackType.CORRECT_SEARCH_QUERY.value,
                  FeedbackType.CORRECT_DOC.value,
                  FeedbackType.CORRECT_RESPONSE.value,
              ]:
                  assert (
                      human_acts[i + 1]["feedback_type"]
                      == bot_act["improve_bucket"]
                  )
                  new_context_texts = [
                      normalize_reply(human_acts[0]["text"])
                  ]
                  if self.add_bot_failure_to_feedback_input:
                      if (
                          self.add_knowledge_sentence_to_feedback_input
                          and woi_consts.SELECTED_SENTENCES
                          in woi_format_gold_docs
                          and woi_format_gold_docs[
                              woi_consts.SELECTED_SENTENCES
                          ]
                      ):
                          new_context_texts.append(
                              get_knowledge_sentence_with_special_tokens_only(
                                  woi_format_gold_docs[
                                      woi_consts.SELECTED_SENTENCES
                                  ][-1],
                                  normalize_knowledge=True,
                              )
                          )
                      new_context_texts.append(
                          normalize_reply(bot_act["text"])
                      )
  
                  feedback_examples.append(
                      {
                          "text": "\n".join(
                              perfect_dialog_context
                              + [t for t in new_context_texts]
                          ),
                          "labels": [
                              normalize_reply(human_acts[i + 1]["text"])
                          ],
                          "last_nonperfect_feedback": bot_act[
                              "improve_bucket"
                          ],
                          "bot_failure_text": bot_act["text"],
                          **(copy.deepcopy(woi_format_gold_docs)),
                      }
                  )
                  if "search_queries" in bot_act:
                      feedback_examples[-1]["search_queries"] = bot_act[
                          "search_queries"
                      ]
                  if "selected_sentences" in effective_human_feedback:
                      feedback_examples[-1][
                          "selected_sentences"
                      ] = effective_human_feedback["selected_sentences"]
  
      effective_human_feedback["feedback_chain"] = feedback_chain
      effective_human_feedback["last_nonperfect_feedback"] = (
          feedback_chain[-2]
          if len(bot_acts) > 1
          else FeedbackType.NONE.value
      )
  
      # remove redundant examples
      human_revision["search_query"] = dedup_list(
          human_revision["search_query"]
      )
      bot_gold["search_query"] = dedup_list(
          [
              q
              for q in bot_gold["search_query"]
              if q not in human_revision["search_query"]
          ]
      )
      human_revision["selected_sentences"] = dedup_list(
          human_revision["selected_sentences"]
      )
  
      perfect_bot_utt_with_feedback = {
          "text": bot_acts[-1]["text"],
          "human_revision": human_revision,
          "bot_gold": bot_gold,
          "bot_no_feedback": bot_no_feedback,
          "bot_modular_failure": bot_modular_failure,
          "human_acts": human_acts,
          "bot_acts": bot_acts,
      }
      for k, v in effective_human_feedback.items():
          if v is not None:
              perfect_bot_utt_with_feedback[k] = v
  
      if woi_format_gold_docs:
          for k, v in woi_format_gold_docs.items():
              if k in perfect_bot_utt_with_feedback:
                  raise RuntimeError(
                      "name collision in continual learning task"
                  )
              perfect_bot_utt_with_feedback[k] = v
  
      return [
          {"text": human_acts[0]["text"]},
          perfect_bot_utt_with_feedback,
      ], feedback_examples
  
imports: import os
  import copy
  import json
  import random
  from typing import Optional
  from parlai.utils.misc import warn_once
  from parlai.utils.data import DatatypeHelper
  from parlai.core.opt import Opt
  from parlai.core.teachers import DialogTeacher
  from parlai.core.params import ParlaiParser
  from parlai.core.message import Message
  from parlai.utils.io import PathManager
  from parlai.tasks.wizard_of_internet import constants
  from .mutators import normalize_reply, get_knowledge_appended_context, get_knowledge_sentence_with_special_tokens_only
  from .build import build
  from .constants import FeedbackType, TITLE_PASSAGE_DELIMITER, OK_LABEL, NOT_OK_LABEL
label_desc: Use image node_id 5 for calling the FitsBaseTeacher obj's underlying member method code with example usage: obj._add_feedback_to_perfect_utt(bot_acts, human_acts, perfect_dialog_context) and returns: list,  feedback_examples