code: def violates_moderation(text):
      """
      Check whether the text violates OpenAI moderation API.
      """
      url = "https://api.openai.com/v1/moderations"
      headers = {
          "Content-Type": "application/json",
          "Authorization": "Bearer " + os.environ["OPENAI_API_KEY"],
      }
      text = text.replace("\n", "")
      data = "{" + '"input": ' + f'"{text}"' + "}"
      data = data.encode("utf-8")
      try:
          ret = requests.post(
              url, headers=headers, data=data, timeout=5
          )
          flagged = ret.json()["results"][0]["flagged"]
      except requests.exceptions.RequestException as e:
          flagged = False
      except KeyError as e:
          flagged = False
  
      return flagged
  
file_path: ml-ferret/ferret/utils.py
imports: import datetime
  import logging
  import logging.handlers
  import os
  import sys
  import requests
  from ferret.constants import LOGDIR
label_desc: Use image node_id 3 for calling a global function with example usage: violates_moderation(text) and returns: flagged