code: def generate_event(
      event_type: metadata_store_pb2.Event.Type,
      key: str,
      index: int,
      artifact_id: Optional[int] = None,
      execution_id: Optional[int] = None,
  ) -> metadata_store_pb2.Event:
      """Generates a MLMD event given type, key and index.
  
      Args:
        event_type: The type of the event. e.g., INPUT, OUTPUT, etc.
        key: The key of the input or output channel. Usually a key can uniquely
          identify a channel of a TFX node.
        index: The index of the artifact in a channel. For example, a trainer might
          take more than one Example artifacts in one of its input channels. We need
          to distinguish each artifact when creating events.
        artifact_id: Optional artifact id for the event.
        execution_id: Optional execution id for the event.
  
      Returns:
        A metadata_store_pb2.Event message.
      """
      event = metadata_store_pb2.Event()
      event.type = event_type
      # The order matters, we always use the first step to store key and the second
      # step to store index.
      event.path.steps.add().key = key
      event.path.steps.add().index = index
      if artifact_id:
          event.artifact_id = artifact_id
      if execution_id:
          event.execution_id = execution_id
  
      return event
  
file_path: tfx/tfx/orchestration/portable/mlmd/event_lib.py
imports: import collections
  import contextlib
  from typing import Dict, List, Optional, Sequence, Tuple, TypeVar
  from tfx import types
  from ml_metadata.proto import metadata_store_pb2
label_desc: Use image node_id 10 for calling a global function with example usage: generate_event(event_type, key, index, artifact_id, execution_id) and returns: event