code: def is_valid_model_id(
      model_id: Optional[str],
      region: Optional[str] = None,
      model_version: Optional[str] = None,
      script: enums.JumpStartScriptScope = enums.JumpStartScriptScope.INFERENCE,
      sagemaker_session: Optional[
          Session
      ] = constants.DEFAULT_JUMPSTART_SAGEMAKER_SESSION,
  ) -> bool:
      """Returns True if the model ID is supported for the given script.
  
      Raises:
          ValueError: If the script is not supported by JumpStart.
      """
      if model_id in {None, ""}:
          return False
      if not isinstance(model_id, str):
          return False
  
      s3_client = (
          sagemaker_session.s3_client if sagemaker_session else None
      )
      region = region or constants.JUMPSTART_DEFAULT_REGION_NAME
      model_version = model_version or "*"
  
      models_manifest_list = (
          accessors.JumpStartModelsAccessor._get_manifest(
              region=region, s3_client=s3_client
          )
      )
      model_id_set = {model.model_id for model in models_manifest_list}
      if script == enums.JumpStartScriptScope.INFERENCE:
          return model_id in model_id_set
      if script == enums.JumpStartScriptScope.TRAINING:
          return model_id in model_id_set
      raise ValueError(f"Unsupported script: {script}")
  
imports: from __future__ import absolute_import
  import logging
  import os
  from typing import Any, Dict, List, Optional, Union
  from urllib.parse import urlparse
  import boto3
  from packaging.version import Version
  import sagemaker
  from sagemaker.config.config_schema import MODEL_ENABLE_NETWORK_ISOLATION_PATH, MODEL_EXECUTION_ROLE_ARN_PATH, TRAINING_JOB_ENABLE_NETWORK_ISOLATION_PATH, TRAINING_JOB_INTER_CONTAINER_ENCRYPTION_PATH, TRAINING_JOB_ROLE_ARN_PATH
  from sagemaker.jumpstart import constants, enums
  from sagemaker.jumpstart import accessors
  from sagemaker.s3 import parse_s3_url
  from sagemaker.jumpstart.exceptions import DeprecatedJumpStartModelError, VulnerableJumpStartModelError, get_old_model_version_msg
  from sagemaker.jumpstart.types import JumpStartModelHeader, JumpStartModelSpecs, JumpStartVersionedModelId
  from sagemaker.session import Session
  from sagemaker.config import load_sagemaker_config
  from sagemaker.utils import resolve_value_from_config, TagsDict
  from sagemaker.workflow import is_pipeline_variable
label_desc: Use image node_id 21 for calling a global function with example usage: is_valid_model_id(model_id, region, model_version, script, sagemaker_session) and returns: False, False, unknown, unknown