code: def list_jumpstart_models(  # pylint: disable=redefined-builtin
      filter: Union[Operator, str] = Constant(BooleanValues.TRUE),
      region: str = JUMPSTART_DEFAULT_REGION_NAME,
      list_incomplete_models: bool = False,
      list_old_models: bool = False,
      list_versions: bool = False,
      sagemaker_session: Session = DEFAULT_JUMPSTART_SAGEMAKER_SESSION,
  ) -> List[Union[Tuple[str], Tuple[str, str]]]:
      """List models for JumpStart, and optionally apply filters to result.
  
      Args:
          filter (Union[Operator, str]): Optional. The filter to apply to list models. This can be
              either an ``Operator`` type filter (e.g. ``And("task == ic", "framework == pytorch")``),
              or simply a string filter which will get serialized into an Identity filter.
              (e.g. ``"task == ic"``). If this argument is not supplied, all models will be listed.
              (Default: Constant(BooleanValues.TRUE)).
          region (str): Optional. The AWS region from which to retrieve JumpStart metadata regarding
              models. (Default: JUMPSTART_DEFAULT_REGION_NAME).
          list_incomplete_models (bool): Optional. If a model does not contain metadata fields
              requested by the filter, and the filter cannot be resolved to a include/not include,
              whether the model should be included. By default, these models are omitted from results.
              (Default: False).
          list_old_models (bool): Optional. If there are older versions of a model, whether the older
              versions should be included in the returned result. (Default: False).
          list_versions (bool): Optional. True if versions for models should be returned in addition
              to the id of the model. (Default: False).
          sagemaker_session (sagemaker.session.Session): Optional. The SageMaker Session to use
              to perform the model search. (Default: DEFAULT_JUMPSTART_SAGEMAKER_SESSION).
      """
  
      model_id_version_dict: Dict[str, List[str]] = dict()
      for model_id, version in _generate_jumpstart_model_versions(
          filter=filter,
          region=region,
          list_incomplete_models=list_incomplete_models,
          sagemaker_session=sagemaker_session,
      ):
          if model_id not in model_id_version_dict:
              model_id_version_dict[model_id] = list()
          model_id_version_dict[model_id].append(Version(version))
  
      if not list_versions:
          return sorted(list(model_id_version_dict.keys()))
  
      if not list_old_models:
          model_id_version_dict = {
              model_id: set([max(versions)])
              for model_id, versions in model_id_version_dict.items()
          }
  
      model_id_version_set: Set[Tuple[str, str]] = set()
      for model_id in model_id_version_dict:
          for version in model_id_version_dict[model_id]:
              model_id_version_set.add((model_id, str(version)))
  
      return sorted(
          list(model_id_version_set),
          key=cmp_to_key(_compare_model_version_tuples),
      )
  
imports: from __future__ import absolute_import
  import copy
  from concurrent.futures import ThreadPoolExecutor, as_completed
  from functools import cmp_to_key
  import json
  from typing import Any, Generator, List, Optional, Tuple, Union, Set, Dict
  from packaging.version import Version
  from sagemaker.jumpstart import accessors
  from sagemaker.jumpstart.constants import DEFAULT_JUMPSTART_SAGEMAKER_SESSION, JUMPSTART_DEFAULT_REGION_NAME
  from sagemaker.jumpstart.enums import JumpStartScriptScope
  from sagemaker.jumpstart.filters import SPECIAL_SUPPORTED_FILTER_KEYS, BooleanValues, Identity, SpecialSupportedFilterKeys
  from sagemaker.jumpstart.filters import Constant, ModelFilter, Operator, evaluate_filter_expression
  from sagemaker.jumpstart.types import JumpStartModelHeader, JumpStartModelSpecs
  from sagemaker.jumpstart.utils import get_jumpstart_content_bucket, get_sagemaker_version, verify_model_region_and_return_specs
  from sagemaker.session import Session
label_desc: Use image node_id 9 for calling a global function with example usage: list_jumpstart_models(filter, region, list_incomplete_models, list_old_models, list_versions, sagemaker_session) and returns: sorted, sorted