code: def generate_and_save_artifact(
      full_name: str,
      *,
      dst_dir: tfds.typing.PathLike,
      overwrite: bool,
      file_extension: str,
      get_artifact_fn: Callable[
          [tf.data.Dataset, tfds.core.DatasetInfo], T
      ],
      save_artifact_fn: Callable[[str, T], None],
  ) -> None:
      """Builds and saves the generated artifact for the dataset in dst_dir.
  
      Args:
        full_name: Name of the dataset to build `dataset`, `dataset/config`.
        dst_dir: Destination where the dataset will be saved (as
          `dataset-config-version`)
        overwrite: If True, recompute the image even if it exists.
        file_extension: File extension of the artifact (e.g. `.png`)
        get_artifact_fn: Function which extracts the dataset artifact to save.
        save_artifact_fn: Function which save the extracted artifact.
      """
      dst_filename = full_name.replace("/", "-") + file_extension
      dst_path = os.path.join(dst_dir, dst_filename)
      # If the file already exists, skip the generation
      if not overwrite and tf.io.gfile.exists(dst_path):
          logging.info(
              f"Skipping generation for {full_name} (already exists)"
          )
          return
  
      logging.info(f"Generating for {full_name}...")
      # Load the dataset.
      builder_name, _, version = full_name.rpartition("/")
      builder = tfds.builder(f"{builder_name}:{version}")
      split_names = list(builder.info.splits.keys())
      if not split_names:
          logging.info(f"Dataset `{full_name}` not generated.")
          return
      elif "train" in split_names:
          split = "train"
      else:
          split = split_names[0]
      ds = builder.as_dataset(split=split, shuffle_files=False)
      if not tf.io.gfile.exists(dst_dir):
          tf.io.gfile.makedirs(dst_dir)
      try:
          artifact = get_artifact_fn(ds.take(10), builder.info)
      except Exception:  # pylint: disable=broad-except
          logging.info(
              f"Generation not supported for dataset `{full_name}`"
          )
          return
  
      save_artifact_fn(dst_path, artifact)
  
file_path: datasets/tensorflow_datasets/scripts/documentation/script_utils.py
imports: import concurrent.futures
  import functools
  import itertools
  import multiprocessing
  import os
  import traceback
  from typing import Any, Callable, List, Optional, TypeVar
  from absl import app
  from absl import logging
  import tensorflow_datasets
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
label_desc: Use image node_id 2 for calling a global function with example usage: generate_and_save_artifact(full_name) without return types