code: def value_converter(
      tfx_value: Any,
  ) -> Optional[pipeline_pb2.ValueOrRuntimeParameter]:
      """Converts TFX/MLMD values into Kubeflow pipeline ValueOrRuntimeParameter."""
      if tfx_value is None:
          return None
  
      result = pipeline_pb2.ValueOrRuntimeParameter()
      if isinstance(tfx_value, (int, float, str)):
          result.constant_value.CopyFrom(get_kubeflow_value(tfx_value))
      elif isinstance(tfx_value, (Dict, List)):
          result.constant_value.CopyFrom(
              pipeline_pb2.Value(string_value=json.dumps(tfx_value))
          )
      elif isinstance(tfx_value, data_types.RuntimeParameter):
          # Attach the runtime parameter to the context.
          parameter_utils.attach_parameter(tfx_value)
          result.runtime_parameter = tfx_value.name
      elif isinstance(tfx_value, metadata_store_pb2.Value):
          if tfx_value.WhichOneof("value") == "int_value":
              result.constant_value.CopyFrom(
                  pipeline_pb2.Value(int_value=tfx_value.int_value)
              )
          elif tfx_value.WhichOneof("value") == "double_value":
              result.constant_value.CopyFrom(
                  pipeline_pb2.Value(
                      double_value=tfx_value.double_value
                  )
              )
          elif tfx_value.WhichOneof("value") == "string_value":
              result.constant_value.CopyFrom(
                  pipeline_pb2.Value(
                      string_value=tfx_value.string_value
                  )
              )
      elif isinstance(tfx_value, message.Message):
          result.constant_value.CopyFrom(
              pipeline_pb2.Value(
                  string_value=json_format.MessageToJson(
                      message=tfx_value, sort_keys=True
                  )
              )
          )
      else:
          # By default will attempt to encode the object using json_utils.dumps.
          result.constant_value.CopyFrom(
              pipeline_pb2.Value(
                  string_value=json_utils.dumps(tfx_value)
              )
          )
      return result
  
imports: import itertools
  import json
  import os
  import re
  from typing import Any, Dict, List, Mapping, Optional, Type, Union
  from kfp.pipeline_spec import pipeline_spec_pb2
  from tfx import types
  from tfx.dsl.io import fileio
  from tfx.orchestration import data_types
  from tfx.orchestration.kubeflow.v2 import parameter_utils
  from tfx.proto.orchestration import placeholder_pb2
  from tfx.types import artifact
  from tfx.types import channel
  from tfx.types import standard_artifacts
  from tfx.types.experimental import simple_artifacts
  from tfx.utils import json_utils
  from tfx.utils import name_utils
  import yaml
  from google.protobuf import struct_pb2
  from google.protobuf import json_format
  from google.protobuf import message
  from ml_metadata.proto import metadata_store_pb2
label_desc: Use image node_id 8 for calling a global function with example usage: value_converter(tfx_value) and returns: result, None