code: def _collapse_multi_msgs(history, multi_msg_delim):
      """
      This dataset allows for a single user to send multiple messages in a row.
  
      Here we use a delimiter to represent this, like: "Hey!|Nice to meet you."
      """
      collapsed = []
      last_msg = history[0]
      for msg in history[1:]:
          if last_msg["uid"] == msg["uid"]:
              last_msg["text"] = multi_msg_delim.join(
                  (last_msg["text"], msg["text"])
              )
          else:
              collapsed.append(last_msg)
              last_msg = msg
      # don't forget to add back the last message!
      collapsed.append(last_msg)
      return collapsed
  
imports: import copy
  import json
  import os
  from enum import Enum
  from typing import List, Optional, Tuple
  from parlai.core.message import Message
  from parlai.core.metrics import F1Metric
  from parlai.core.mutators import EpisodeMutator, MessageMutator, register_mutator
  from parlai.core.opt import Opt
  from parlai.core.params import ParlaiParser
  from parlai.core.teachers import DialogTeacher
  from parlai.tasks.cmu_dog.build import build
  from parlai.tasks.wizard_of_wikipedia.agents import RareWordF1Calculator, TOKEN_KNOWLEDGE, TOKEN_END_KNOWLEDGE
  from parlai.utils.data import DatatypeHelper
  from parlai.utils.io import PathManager
  from parlai.utils.logging import logger
  from parlai.utils.typing import TShared
label_desc: Use image node_id 4 for calling a global function with example usage: _collapse_multi_msgs(history, multi_msg_delim) and returns: collapsed