code: def collect_task_data_and_model_response(
      model_wrapper,
      opt: Opt,
      task_name: str,
      task_specific_opt: Dict = None,
      num_examples: int = -1,
      filter_func: Callable[[Dict[Any, Any]], Optional[str]] = None,
      save_teacher_acts: bool = False,
  ) -> Tuple[Union[List[str], List[Dict]], List[str]]:
      """
      Helper function to load task data and get a wrapper's responses to it.
  
      Loads up a ParlAI world with a Repeat Label Agent in order to extract
      ParlAI data from a specific teacher. Then, feed this data to the wrapper agent
      to collect the model's responses.
  
      Returns two lists: the first is the model inputs and the second is the model responses
      """
      opt = deepcopy(opt)
      # add teacher specific args
      opt["task"] = task_name
      if task_specific_opt is not None:
          for k, v in task_specific_opt.items():
              opt[k] = v
      # create world
      agent = RepeatLabelAgent(opt)
      world = create_task(opt, agent)
      # get all examples
      model_inputs = []
      num_exs = (
          min(num_examples, world.num_examples())
          if num_examples > 0
          else world.num_examples()
      )
      if opt.get("debug"):
          num_exs = DEBUG_NUM
  
      i = 0
      teacher_acts = []
      while len(model_inputs) < num_exs and i < world.num_examples():
          world.parley()
          act = world.get_acts()[0]
          if filter_func is not None:
              filtered = filter_func(act)
              if filtered is not None:
                  model_inputs.append(filtered)
              # else, continue
          else:
              teacher_acts.append(act)
              model_inputs.append(act["text"])
          i += 1
  
      # get all model responses
      model_responses = collect_model_responses(
          model_wrapper, model_inputs
      )
  
      if opt.get("debug"):
          logging.warning(f"Model responses to task: {task_name}")
          for inp, resp in zip(model_inputs, model_responses):
              print(f"{inp}\n\t{color.BLUE}{resp}{color.END}\n")
  
      if save_teacher_acts:
          return teacher_acts, model_responses
  
      return model_inputs, model_responses
  
file_path: ParlAI/projects/safety_bench/utils/safety_testing.py
imports: from copy import deepcopy
  import json
  import os
  from typing import Dict, List, Tuple, Any, Callable, Optional, Union
  from tqdm import tqdm
  import random
  from parlai.agents.repeat_label.repeat_label import RepeatLabelAgent
  from parlai.core.worlds import create_task
  from parlai.core.opt import Opt
  from parlai.utils import logging
  from parlai.utils.safety import OffensiveLanguageClassifier, OffensiveStringMatcher
  from projects.safety_bench.utils.colors import color
  from projects.safety_bench.utils.perspective_api import PerspectiveAPIClientManager
label_desc: Use image node_id 2 for calling a global function with example usage: collect_task_data_and_model_response(model_wrapper, opt, task_name, task_specific_opt, num_examples, filter_func, save_teacher_acts) and returns: model_inputs,  model_responses, teacher_acts,  model_responses