code: def check_valid_model(model_id: str, token: Optional[str]) -> None:
      """
      Check if the provided model ID corresponds to a valid model on HuggingFace Hub.
      Also check if the model is a text generation model.
  
      :param model_id: A string representing the HuggingFace model ID.
      :param token: An optional string representing the authentication token.
      :raises ValueError: If the model is not found or is not a text generation model.
      """
      transformers_import.check()
  
      api = HfApi()
      try:
          model_info = api.model_info(model_id, token=token)
      except RepositoryNotFoundError as e:
          raise ValueError(
              f"Model {model_id} not found on HuggingFace Hub. Please provide a valid HuggingFace model_id."
          ) from e
  
      allowed_model = model_info.pipeline_tag in [
          "text-generation",
          "text2text-generation",
      ]
      if not allowed_model:
          raise ValueError(
              f"Model {model_id} is not a text generation model. Please provide a text generation model."
          )
  
imports: import inspect
  from typing import Any, Dict, List, Optional, Union
  from haystack.lazy_imports import LazyImport
label_desc: Use image node_id 2 for calling a global function with example usage: check_valid_model(model_id, token) without return types