code: def run_safety_unit_tests(opt):
      get_perspective_api_key(
          opt
      )  # try loading Perspective API key if it exists
      _check_log_dir(opt["log_folder"])
      wrapper_name = opt["wrapper"]
      wrapper = load_wrapper_module(wrapper_name)()
  
      # Tests that check for generating offensive language
      if opt["tests_to_run"] in ["all", "generate"]:
          gen_report = generate_offensive_language_test.main(
              wrapper, opt
          )
      else:
          gen_report = None
  
      # Tests that check the appropriateness of response to offensive language
      if opt["tests_to_run"] in ["all", "response"]:
          resp_report = response_to_offensive_language_test.main(
              wrapper, opt
          )
      else:
          resp_report = None
  
      if opt.get("debug"):
          logging.error(
              "WARNING: ran in debug mode. Numbers are incorrect"
          )
  
      # generate the rainbow stars
      stars = (
          "".join(
              [
                  col + "*" * (60 // len(color.RAINBOW))
                  for col in color.RAINBOW
              ]
          )
          + color.END
      )
      print("\n\n" + stars)
      print(
          f"{color.CYAN}{color.BOLD}{color.UNDERLINE}Safety Unit Tests: Report for {wrapper_name} {color.END}"
      )
      if gen_report is not None:
          # generation metrics
          _pretty_report("Unsafe Generation", gen_report)
      if resp_report is not None:
          # response metrics
          _pretty_report("Response to Offensive Language", resp_report)
  
      print(stars + "\n\n")
      print(
          f"All model logs -- including safety scores -- can be found in {color.YELLOW}{opt['log_folder']}{color.END}."
      )
      _interpret_results()
      _disclaimer()
  
file_path: ParlAI/projects/safety_bench/run_unit_tests.py
imports: from parlai.core.params import ParlaiParser
  from parlai.core.script import ParlaiScript
  import parlai.utils.logging
  from projects.safety_bench.utils.wrapper_loading import load_wrapper_module, setup_wrapper_registry, register_model_wrapper, MODEL_WRAPPER_REGISTRY
  from projects.safety_bench.unit_tests import generate_offensive_language_test, response_to_offensive_language_test
  from projects.safety_bench.utils.colors import color
  from projects.safety_bench.utils.perspective_api import get_perspective_api_key
  import os
  from typing import Optional
label_desc: Use image node_id 6 for calling a global function with example usage: run_safety_unit_tests(opt) without return types