code: def serve_by_page(
      pageable_resp: bindings.Paginated,
      pageable_type: str,
      max_page_size: int,
  ) -> Callable[[requests.PreparedRequest], Tuple[int, Dict, str]]:
      """Create a callback for responses that serves a paginated response.
  
      Pages will be created from a complete response based on the request's param's offset and limit.
  
      Args:
          pageable_resp: A complete response that can be paginated
          pageable_type: The name of the field in the response that will be split up across pages when
            a response is paginated
          max_page_size: The maximum number of items to include in each page. If a request's params
            specify a limit that is larger than this (or no limit at all), the limit will be reduced
            to this value
  
      Returns:
          A function that returns a page of a response based on a request's params
          (and this function's args)
  
          The precise return value (required by responses) is a tuple of (status_code, headers, body).
      """
  
      def _serve_by_page(
          request: requests.PreparedRequest,
      ) -> Tuple[int, Dict, str]:
          # ignore type checking on request.params -- responses guarantees params is populated
          limit = min(int(request.params.get("limit", max_page_size)), max_page_size)  # type: ignore
          paged_response = page_of(
              pageable_resp,
              pageable_type,
              offset=int(request.params.get("offset", 0)),  # type: ignore
              limit=limit,
          )
          return (200, {}, json.dumps(paged_response.to_json()))
  
      return _serve_by_page
  
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 19 for calling a global function with example usage: serve_by_page(pageable_resp, pageable_type, max_page_size) and returns: _serve_by_page, int,  dict,  json