code: def _do_pull_model(
      self,
      tag: str | Tag,
      download_task_id: TaskID,
      *,
      force: bool = False,
      model_store: ModelStore = Provide[BentoMLContainer.model_store],
      context: str | None = None,
      query: str | None = None,
  ) -> Model:
      _tag = Tag.from_taglike(tag)
      try:
          model = model_store.get(_tag)
      except NotFound:
          model = None
      else:
          if _tag.version not in (None, "latest"):
              if not force:
                  self.log_progress.add_task(
                      f'[bold blue]Model "{tag}" already exists locally, skipping'
                  )
                  return model
              else:
                  model_store.delete(tag)
      yatai_rest_client = get_rest_api_client(context)
      name = _tag.name
      version = _tag.version
      if version in (None, "latest"):
          latest_model = yatai_rest_client.get_latest_model(
              name, query=query
          )
          if latest_model is None:
              raise BentoMLException(
                  f'Model "{_tag}" not found on remote model store, you may need to specify a version'
              )
          if model is not None:
              if (
                  not force
                  and latest_model.build_at < model.creation_time
              ):
                  self.log_progress.add_task(
                      f'[bold blue]Newer version of model "{name}" exists locally, skipping'
                  )
                  return model
              if model.tag.version == latest_model.version:
                  if not force:
                      self.log_progress.add_task(
                          f'[bold blue]Model "{model.tag}" already exists locally, skipping'
                      )
                      return model
                  else:
                      model_store.delete(model.tag)
          version = latest_model.version
      elif query:
          warnings.warn(
              "`query` is ignored when model version is specified",
              UserWarning,
          )
  
      with self.spin(
          text=f'Getting a presigned download url for model "{_tag}"..'
      ):
          remote_model = yatai_rest_client.presign_model_download_url(
              name, version
          )
  
      if not remote_model:
          raise BentoMLException(
              f'Model "{_tag}" not found on remote model store'
          )
  
      # Download model files from remote model store
      transmission_strategy: TransmissionStrategy = "proxy"
      presigned_download_url: str | None = None
  
      if remote_model.transmission_strategy is not None:
          transmission_strategy = remote_model.transmission_strategy
      else:
          with self.spin(
              text=f'Getting a presigned download url for model "{_tag}"'
          ):
              remote_model = (
                  yatai_rest_client.presign_model_download_url(
                      name, version
                  )
              )
              if remote_model.presigned_download_url:
                  presigned_download_url = (
                      remote_model.presigned_download_url
                  )
                  transmission_strategy = "presigned_url"
  
      if transmission_strategy == "proxy":
          response = yatai_rest_client.download_model(
              model_repository_name=name, version=version
          )
      else:
          if presigned_download_url is None:
              with self.spin(
                  text=f'Getting a presigned download url for model "{_tag}"'
              ):
                  remote_model = (
                      yatai_rest_client.presign_model_download_url(
                          name, version
                      )
                  )
                  presigned_download_url = (
                      remote_model.presigned_download_url
                  )
  
          response = requests.get(presigned_download_url, stream=True)
          if response.status_code != 200:
              raise BentoMLException(
                  f'Failed to download model "{_tag}": {response.text}'
              )
  
      total_size_in_bytes = int(
          response.headers.get("content-length", 0)
      )
      block_size = 1024  # 1 Kibibyte
      with NamedTemporaryFile() as tar_file:
          self.transmission_progress.update(
              download_task_id,
              description=f'Downloading model "{_tag}"',
              total=total_size_in_bytes,
              visible=True,
          )
          self.transmission_progress.start_task(download_task_id)
          for data in response.iter_content(block_size):
              self.transmission_progress.update(
                  download_task_id, advance=len(data)
              )
              tar_file.write(data)
          self.log_progress.add_task(
              f'[bold green]Finished downloading model "{_tag}" files'
          )
          tar_file.seek(0, 0)
          tar = tarfile.open(fileobj=tar_file, mode="r")
          with self.spin(text=f'Extracting model "{_tag}" tar file'):
              with fs.open_fs("temp://") as temp_fs:
                  for member in tar.getmembers():
                      f = tar.extractfile(member)
                      if f is None:
                          continue
                      p = Path(member.name)
                      if p.parent != Path("."):
                          temp_fs.makedirs(str(p.parent), recreate=True)
                      temp_fs.writebytes(member.name, f.read())
                  model = Model.from_fs(temp_fs).save(model_store)
                  self.log_progress.add_task(
                      f'[bold green]Successfully pulled model "{_tag}"'
                  )
                  return model
  
imports: from __future__ import annotations
  import tarfile
  import tempfile
  import threading
  import typing
  import warnings
  from concurrent.futures import ThreadPoolExecutor
  from pathlib import Path
  from tempfile import NamedTemporaryFile
  import fs
  import requests
  from rich.live import Live
  from simple_di import Provide
  from simple_di import inject
  from ...exceptions import BentoMLException
  from ...exceptions import NotFound
  from ..bento import Bento
  from ..bento import BentoStore
  from ..configuration.containers import BentoMLContainer
  from ..models import Model
  from ..models import ModelStore
  from ..models import copy_model
  from ..tag import Tag
  from ..utils import calc_dir_size
  from .base import FILE_CHUNK_SIZE
  from .base import CallbackIOWrapper
  from .base import CloudClient
  from .config import get_rest_api_client
  from .deployment import Deployment
  from .schemas import BentoApiSchema
  from .schemas import BentoManifestSchema
  from .schemas import BentoRunnerResourceSchema
  from .schemas import BentoRunnerSchema
  from .schemas import BentoUploadStatus
  from .schemas import CompleteMultipartUploadSchema
  from .schemas import CompletePartSchema
  from .schemas import CreateBentoRepositorySchema
  from .schemas import CreateBentoSchema
  from .schemas import CreateModelRepositorySchema
  from .schemas import CreateModelSchema
  from .schemas import FinishUploadBentoSchema
  from .schemas import FinishUploadModelSchema
  from .schemas import LabelItemSchema
  from .schemas import ModelManifestSchema
  from .schemas import ModelUploadStatus
  from .schemas import PreSignMultipartUploadUrlSchema
  from .schemas import TransmissionStrategy
  from .schemas import UpdateBentoSchema
label_desc: Use image node_id 9 for calling the BentoCloudClient obj's underlying member method code with example usage: obj._do_pull_model(tag, download_task_id) and returns: model, model, model, model