code: def get_perspective_api_key(opt) -> Optional[str]:
      # check datapath to see if it exists
      datapath = opt["datapath"]
      credentials_path = os.path.join(
          datapath, "safety_tests", ".perspective_api", "credentials"
      )
      api_key = None
      if not os.path.exists(credentials_path):
          # API key has not been requested yet
          api_key = input(
              f"{color.BLUE}If you have an API key for the Perspective API for this project, you can optionally use this "
              "for additional analysis of your models. Please see the terms of use and find more "
              "information here: <https://developers.google.com/terms/>\n\n"
              f"{color.BOLD}If you would like to use the Perspective API, please enter your API key here. Otherwise, "
              f"press enter to continue...\n{color.END}"
          )
          # create directory if does not exist
          directory = os.path.dirname(credentials_path)
          if not os.path.exists(directory):
              os.makedirs(directory)
  
          # write API key
          with open(credentials_path, "w") as f:
              if api_key:
                  f.write(api_key + "\n")
              else:
                  f.write(NO_API_KEY_AVAILABLE)
  
          if not api_key:
              api_key = None
      else:
          # read API key
          with open(credentials_path, "r") as f:
              api_key = f.read().rstrip()
              if api_key == NO_API_KEY_AVAILABLE:
                  api_key = None
  
      if api_key is None:
          logging.warning("No Perspective API key is available.")
      else:
          assert PERSPECTIVE_CLIENT_AVAILABLE, (
              "You must install the perspective API client. "
              "Please run:\n`pip install google-api-python-client`"
              "\nor follow the instructions here:\n"
              "<https://github.com/googleapis/google-api-python-client>"
          )
  
      opt["perspective_api_key"] = api_key
  
file_path: ParlAI/projects/safety_bench/utils/perspective_api.py
imports: import parlai.utils.logging
  from projects.safety_bench.utils.colors import color
  import os
  from typing import Optional
  import time
label_desc: Use image node_id 1 for calling a global function with example usage: get_perspective_api_key(opt) without return types