code: def adapt(msg, to_version=protocol_version_info[0]):
      """Adapt a single message to a target version
  
      Parameters
      ----------
  
      msg : dict
          A Jupyter message.
      to_version : int, optional
          The target major version.
          If unspecified, adapt to the current version.
  
      Returns
      -------
  
      msg : dict
          A Jupyter message appropriate in the new version.
      """
      from .session import utcnow
  
      header = msg["header"]
      if "date" not in header:
          header["date"] = utcnow()
      if "version" in header:
          from_version = int(header["version"].split(".")[0])
      else:
          # assume last version before adding the key to the header
          from_version = 4
      adapter = adapters.get((from_version, to_version), None)
      if adapter is None:
          return msg
      return adapter(msg)
  
imports: import re
  import json
  from jupyter_client import protocol_version_info
label_desc: Use image node_id 4 for calling a global function with example usage: adapt(msg, to_version) and returns: adapter, msg