code: def _get_or_create_experiment_and_trial(
      client: experimental.Determined,
      config_text: str,
      experiment_id: Optional[Union[str, int]] = None,
      trial_id: Optional[Union[str, int]] = None,
      hparams: Optional[dict] = None,
      distributed: Optional[core.DistributedContext] = None,
  ) -> det.ClusterInfo:
      if experiment_id is None:
          if trial_id is None:
              exp_id = _create_unmanaged_experiment(
                  client, config_text, distributed
              )
              trial_id, task_id = _create_unmanaged_trial(
                  client, exp_id, hparams, distributed
              )
              return _build_unmanaged_trial_cluster_info(
                  client,
                  exp_id,
                  trial_id,
                  task_id,
                  config_text,
                  hparams,
                  distributed=distributed,
              )
          elif isinstance(trial_id, int):
              raise NotImplementedError
          elif isinstance(trial_id, str):
              # TODO(ilia): add GetExperimentByExternalTrialId.
              raise NotImplementedError
      elif isinstance(experiment_id, int):
          if trial_id is None:
              raise NotImplementedError
          elif isinstance(trial_id, int):
              raise NotImplementedError
          elif isinstance(trial_id, str):
              raise NotImplementedError
      elif isinstance(experiment_id, str):
          # TODO(ilia): Detect if >1 trials exist in the experiment.
          # If yes, and the experiment searcher config is `single`, patch the experiment
          # to switch the search config to `custom` searcher.
          # This should switch WebUI into hp search UI for these experiments.
          if trial_id is None:
              exp_id = _put_unmanaged_experiment(
                  client, config_text, experiment_id, distributed
              )
              trial_id, task_id = _create_unmanaged_trial(
                  client, exp_id, hparams, distributed
              )
              return _build_unmanaged_trial_cluster_info(
                  client,
                  exp_id,
                  trial_id,
                  task_id,
                  config_text,
                  hparams,
                  distributed=distributed,
              )
          elif isinstance(trial_id, int):
              raise NotImplementedError
          elif isinstance(trial_id, str):
              exp_id = _put_unmanaged_experiment(
                  client, config_text, experiment_id, distributed
              )
              trial_id, task_id = _put_unmanaged_trial(
                  client, exp_id, trial_id, hparams, distributed
              )
              return _build_unmanaged_trial_cluster_info(
                  client,
                  exp_id,
                  trial_id,
                  task_id,
                  config_text,
                  hparams,
                  distributed=distributed,
              )
      else:
          raise ValueError(
              f"experiment_id is neither int nor string: {type(experiment_id)}"
          )
      raise ValueError(
          f"trial_id is neither int nor string: {type(trial_id)}"
      )
  
imports: import logging
  from typing import Callable, Optional, Tuple, TypeVar, Union
  import determined
  from determined import core, experimental
  from determined.common import api, util
  from determined.common.api import bindings
label_desc: Use image node_id 17 for calling a global function with example usage: _get_or_create_experiment_and_trial(client, config_text, experiment_id, trial_id, hparams, distributed) and returns: _build_unmanaged_trial_cluster_info, _build_unmanaged_trial_cluster_info, _build_unmanaged_trial_cluster_info