class_docstr: Class that implements a cache for JumpStart models manifests and specs.
  
  The manifest and specs associated with JumpStart models provide the information necessary
  for launching JumpStart models from the SageMaker SDK.
docstr: Return model ID and version in manifest that matches semantic version/id.
  
  Uses ``packaging.version`` to perform version comparison. The highest model version
  matching the semantic version is used, which is compatible with the SageMaker
  version.
  
  Args:
      key (JumpStartVersionedModelId): Key for which to fetch versioned model ID.
      value (Optional[JumpStartVersionedModelId]): Unused variable for current value of
          old cached model ID/version.
  
  Raises:
      KeyError: If the semantic version is not found in the manifest, or is found but
          the SageMaker version needs to be upgraded in order for the model to be used.
docstr_tok: ["Return","model","ID","and","version","in","manifest","that","matches","semantic","version\/id",".","Uses","``","packaging.version","``","to","perform","version","comparison",".","The","highest","model","version","matching","the","semantic","version","is","used",",","which","is","compatible","with","the","SageMaker","version",".","Args",":","key","(","JumpStartVersionedModelId",")",":","Key","for","which","to","fetch","versioned","model","ID",".","value","(","Optional","[","JumpStartVersionedModelId","]",")",":","Unused","variable","for","current","value","of","old","cached","model","ID\/version",".","Raises",":","KeyError",":","If","the","semantic","version","is","not","found","in","the","manifest",",","or","is","found","but","the","SageMaker","version","needs","to","be","upgraded","in","order","for","the","model","to","be","used","."]
code: def _get_manifest_key_from_model_id_semantic_version(
      self,
      key: JumpStartVersionedModelId,
      value: Optional[
          JumpStartVersionedModelId
      ],  # pylint: disable=W0613
  ) -> JumpStartVersionedModelId:
      """Return model ID and version in manifest that matches semantic version/id.
  
      Uses ``packaging.version`` to perform version comparison. The highest model version
      matching the semantic version is used, which is compatible with the SageMaker
      version.
  
      Args:
          key (JumpStartVersionedModelId): Key for which to fetch versioned model ID.
          value (Optional[JumpStartVersionedModelId]): Unused variable for current value of
              old cached model ID/version.
  
      Raises:
          KeyError: If the semantic version is not found in the manifest, or is found but
              the SageMaker version needs to be upgraded in order for the model to be used.
      """
  
      model_id, version = key.model_id, key.version
  
      manifest = self._s3_cache.get(
          JumpStartCachedS3ContentKey(
              JumpStartS3FileType.MANIFEST, self._manifest_file_s3_key
          )
      )[0].formatted_content
  
      sm_version = utils.get_sagemaker_version()
  
      versions_compatible_with_sagemaker = [
          Version(header.version)
          for header in manifest.values()  # type: ignore
          if header.model_id == model_id
          and Version(header.min_version) <= Version(sm_version)
      ]
  
      sm_compatible_model_version = self._select_version(
          version, versions_compatible_with_sagemaker
      )
  
      if sm_compatible_model_version is not None:
          return JumpStartVersionedModelId(
              model_id, sm_compatible_model_version
          )
  
      versions_incompatible_with_sagemaker = [
          Version(header.version)
          for header in manifest.values()  # type: ignore
          if header.model_id == model_id
      ]
      sm_incompatible_model_version = self._select_version(
          version, versions_incompatible_with_sagemaker
      )
  
      if sm_incompatible_model_version is not None:
          model_version_to_use_incompatible_with_sagemaker = (
              sm_incompatible_model_version
          )
          sm_version_to_use_list = [
              header.min_version
              for header in manifest.values()  # type: ignore
              if header.model_id == model_id
              and header.version
              == model_version_to_use_incompatible_with_sagemaker
          ]
          if len(sm_version_to_use_list) != 1:
              # ``manifest`` dict should already enforce this
              raise RuntimeError(
                  "Found more than one incompatible SageMaker version to use."
              )
          sm_version_to_use = sm_version_to_use_list[0]
  
          error_msg = (
              f"Unable to find model manifest for '{model_id}' with version '{version}' "
              f"compatible with your SageMaker version ('{sm_version}'). "
              f"Consider upgrading your SageMaker library to at least version "
              f"'{sm_version_to_use}' so you can use version "
              f"'{model_version_to_use_incompatible_with_sagemaker}' of '{model_id}'."
          )
          raise KeyError(error_msg)
  
      error_msg = f"Unable to find model manifest for '{model_id}' with version '{version}'. "
      error_msg += (
          f"Visit {MODEL_ID_LIST_WEB_URL} for updated list of models. "
      )
  
      other_model_id_version = self._select_version(
          "*", versions_incompatible_with_sagemaker
      )  # all versions here are incompatible with sagemaker
      if other_model_id_version is not None:
          error_msg += (
              f"Consider using model ID '{model_id}' with version "
              f"'{other_model_id_version}'."
          )
  
      else:
          possible_model_ids = [header.model_id for header in manifest.values()]  # type: ignore
          closest_model_id = get_close_matches(
              model_id, possible_model_ids, n=1, cutoff=0
          )[0]
          error_msg += (
              f"Did you mean to use model ID '{closest_model_id}'?"
          )
  
      raise KeyError(error_msg)
  
imports: from __future__ import absolute_import
  import datetime
  from difflib import get_close_matches
  import os
  from typing import List, Optional, Tuple, Union
  import json
  import boto3
  import botocore
  from packaging.version import Version
  from packaging.specifiers import SpecifierSet, InvalidSpecifier
  from sagemaker.jumpstart.constants import ENV_VARIABLE_JUMPSTART_MANIFEST_LOCAL_ROOT_DIR_OVERRIDE, ENV_VARIABLE_JUMPSTART_SPECS_LOCAL_ROOT_DIR_OVERRIDE, JUMPSTART_DEFAULT_MANIFEST_FILE_S3_KEY, JUMPSTART_DEFAULT_REGION_NAME, JUMPSTART_LOGGER, MODEL_ID_LIST_WEB_URL
  from sagemaker.jumpstart.exceptions import get_wildcard_model_version_msg
  from sagemaker.jumpstart.parameters import JUMPSTART_DEFAULT_MAX_S3_CACHE_ITEMS, JUMPSTART_DEFAULT_MAX_SEMANTIC_VERSION_CACHE_ITEMS, JUMPSTART_DEFAULT_S3_CACHE_EXPIRATION_HORIZON, JUMPSTART_DEFAULT_SEMANTIC_VERSION_CACHE_EXPIRATION_HORIZON
  from sagemaker.jumpstart.types import JumpStartCachedS3ContentKey, JumpStartCachedS3ContentValue, JumpStartModelHeader, JumpStartModelSpecs, JumpStartS3FileType, JumpStartVersionedModelId
  from sagemaker.jumpstart import utils
  from sagemaker.utilities.cache import LRUCache
label_desc: Use image node_id 8 for calling the JumpStartModelsCache obj's underlying member method code with example usage: obj._get_manifest_key_from_model_id_semantic_version(key, value) and returns: JumpStartVersionedModelId