code: def msg_to_str(msg, ignore_fields=""):
      """
      Convert ParlAI message dict to string.
  
      :param msg:
          dict to convert into a string.
      :param ignore_fields:
          (default '') comma-separated field names to not include in the string
          even if they're in the msg dict.
      """
  
      def filter(txt):
          txt = str(txt)
          txt = txt.replace("\t", "\\t")
          txt = txt.replace("\n", "\\n")
          txt = txt.replace("|", "__PIPE__")
          return txt
  
      def add_field(name, data):
          if name == "reward" and data == 0:
              return ""
          if name == "episode_done" and data is False:
              return ""
          txt = ""
          if (
              type(data) == tuple
              or type(data) == set
              or type(data) == list
          ):
              # list entries
              for c in data:
                  txt += filter(c) + "|"
              txt = txt[:-1]
          else:
              # single fields
              txt = filter(data)
          return name + ":" + txt + "\t"
  
      default_fields = [
          "id",
          "text",
          "labels",
          "label_candidates",
          "episode_done",
          "reward",
      ]
      txt = ""
      ignore_fields = ignore_fields.split(",")
      for f in default_fields:
          if f in msg and f not in ignore_fields:
              txt += add_field(f, msg[f])
      for f in msg.keys():
          if f not in default_fields and f not in ignore_fields:
              txt += add_field(f, msg[f])
      return txt.rstrip("\t")
  
imports: from collections import deque, OrderedDict
  from typing import Union, Optional, Set, Any, Dict, List, Tuple
  from datetime import timedelta
  import functools
  import math
  import time
  import re
  import shutil
  import json
  import os
  from parlai.core.message import Message
  from parlai.utils.strings import colorize
  from parlai.utils.io import PathManager
  import parlai.utils.logging
label_desc: Use image node_id 12 for calling a global function with example usage: msg_to_str(msg, ignore_fields) and returns: txt, txt, unknown, str, str