class_docstr: Internal W&B Artifact model storage.
  
  _model_type_id: (str) The id of the SavedModel subclass used to serialize the model.
class_docstr_tok: ["Internal","W","&","B","Artifact","model","storage",".","_model_type_id",":","(","str",")","The","id","of","the","SavedModel","subclass","used","to","serialize","the","model","."]
code: def to_json(
      self, run_or_artifact: Union["LocalRun", "Artifact"]
  ) -> dict:
      # Unlike other data types, we do not allow adding to a Run directly. There is a
      # bit of tech debt in the other data types which requires the input to `to_json`
      # to accept a Run or Artifact. However, Run additions should be deprecated in the future.
      # This check helps ensure we do not add to the debt.
      if isinstance(run_or_artifact, wandb.wandb_sdk.wandb_run.Run):
          raise ValueError(
              "SavedModel cannot be added to run - must use artifact"
          )
      artifact = run_or_artifact
      json_obj = {
          "type": self._log_type,
      }
      assert (
          self._path is not None
      ), "Cannot add SavedModel to Artifact without path"
      if os.path.isfile(self._path):
          # If the path is a file, then we can just add it to the artifact,
          # First checking to see if the artifact already has the file (use the cache)
          # Else, add it directly, allowing the artifact adder to rename the file deterministically.
          already_added_path = artifact.get_added_local_path_name(
              self._path
          )
          if already_added_path is not None:
              json_obj["path"] = already_added_path
          else:
              target_path = os.path.join(
                  ".wb_data",
                  "saved_models",
                  os.path.basename(self._path),
              )
              json_obj["path"] = artifact.add_file(
                  self._path, target_path, True
              ).path
      elif os.path.isdir(self._path):
          # If the path is a directory, then we need to add all of the files
          # The directory must be named deterministically based on the contents of the directory,
          # but the files themselves need to have their name preserved.
          # FUTURE: Add this functionality to the artifact adder itself
          json_obj["path"] = _add_deterministic_dir_to_artifact(
              artifact,
              self._path,
              os.path.join(".wb_data", "saved_models"),
          )
      else:
          raise ValueError(
              f"Expected a path to a file or directory, got {self._path}"
          )
  
      return json_obj
  
imports: import os
  import shutil
  import sys
  from typing import TYPE_CHECKING, Any, ClassVar, Generic, List, Optional, Type, TypeVar, Union, cast
  import wandb
  from wandb import util
  from wandb.sdk.lib import runid
  from wandb.sdk.lib.hashutil import md5_file_hex
  from wandb.sdk.lib.paths import LogicalPath
  from ._private import MEDIA_TMP
  from .base_types.wb_value import WBValue
label_desc: Use image node_id 4 for calling the _SavedModel obj's underlying member method code with example usage: obj.to_json(run_or_artifact) and returns: json_obj