code: def page_of(
      complete_resp: P,
      pageable_type: str,
      offset: int = 0,
      limit: Optional[int] = None,
  ) -> P:
      """Return a paginated response from a complete response.
  
      This assumes that the passed `complete_resp` contains an attribute named `pageable_type` that
      can be broken up into pages.
  
      Args:
          complete_resp: A complete response that can be paginated
          pageable_type: The name of the attribute of the complete_resp that can be paginated
          offset: If positive, the number of attributes to start the page from. If negative, indexed
            from the end.
          limit: The maximum number of attributes to include in the page. If None, include all
            attributes.
  
      Returns:
          A copy of the complete_resp wherein:
              - the pageable_type attribute has been sliced into a single page
              - a new pagination attribute has been created from passed offset and limit
      """
      if not hasattr(complete_resp, pageable_type):
          raise ValueError(
              f"Response does not have a {pageable_type} attribute"
          )
      if not isinstance(
          getattr(complete_resp, pageable_type), Iterable
      ):
          raise ValueError(f"Attribute {pageable_type} is not pageable")
  
      paged_resp = copy.deepcopy(complete_resp)
      total = len(getattr(complete_resp, pageable_type))
      start_index = (
          offset if offset >= 0 else total + offset
      )  # Negative offset means from the end
      end_index = (
          total if limit is None else min(start_index + limit, total)
      )
  
      paged_resp.pagination = bindings.v1Pagination(
          endIndex=end_index,
          limit=limit,
          offset=offset,
          startIndex=start_index,
          total=total,
      )
  
      page = getattr(paged_resp, pageable_type)[start_index:end_index]
      setattr(paged_resp, pageable_type, page)
  
      return paged_resp
  
imports: import copy
  import json
  import pathlib
  from typing import Any, Callable, Dict, Iterable, Iterator, Optional, Tuple, TypeVar
  import requests
  from determined.common.api import bindings
label_desc: Use image node_id 18 for calling a global function with example usage: page_of(complete_resp, pageable_type, offset, limit) and returns: paged_resp