class_docstr: The torchserve side inference and explain end-points requests are handled to
  return a KServe side response
  
  Args:
      kserve.KFModel(class object): The predict and explain methods are overridden by torchserve
      side predict and explain http requests.
docstr: This method converts the v2 infer response types to gRPC or REST.
  For gRPC request it converts InferResponse to gRPC message or directly returns ModelInferResponse from
  predictor call or converts TS PredictionResponse to ModelInferResponse.
  For REST request it converts ModelInferResponse to Dict or directly returns from predictor call.
  
  Args:
      response (Dict|InferResponse|ModelInferResponse|PredictionResponse): The response passed from ``predict`` handler.
      headers (Dict): Request headers.
  
  Returns:
      Dict: post-processed response.
docstr_tok: ["This","method","converts","the","v2","infer","response","types","to","gRPC","or","REST",".","For","gRPC","request","it","converts","InferResponse","to","gRPC","message","or","directly","returns","ModelInferResponse","from","predictor","call","or","converts","TS","PredictionResponse","to","ModelInferResponse",".","For","REST","request","it","converts","ModelInferResponse","to","Dict","or","directly","returns","from","predictor","call",".","Args",":","response","(","Dict|InferResponse|ModelInferResponse|PredictionResponse",")",":","The","response","passed","from","``","predict","``","handler",".","headers","(","Dict",")",":","Request","headers",".","Returns",":","Dict",":","post-processed","response","."]
code: def postprocess(
      self,
      response: Union[
          Dict, InferResponse, ModelInferResponse, PredictionResponse
      ],
      headers: Dict[str, str] = None,
  ) -> Union[Dict, ModelInferResponse]:
      """This method converts the v2 infer response types to gRPC or REST.
      For gRPC request it converts InferResponse to gRPC message or directly returns ModelInferResponse from
      predictor call or converts TS PredictionResponse to ModelInferResponse.
      For REST request it converts ModelInferResponse to Dict or directly returns from predictor call.
  
      Args:
          response (Dict|InferResponse|ModelInferResponse|PredictionResponse): The response passed from ``predict`` handler.
          headers (Dict): Request headers.
  
      Returns:
          Dict: post-processed response.
      """
      if headers:
          if "grpc" in headers.get("user-agent", ""):
              if isinstance(response, ModelInferResponse):
                  return response
              elif isinstance(response, InferResponse):
                  return response.to_grpc()
              elif isinstance(response, PredictionResponse):
                  return from_ts_grpc(response)
          if "application/json" in headers.get("content-type", ""):
              # If the original request is REST, convert the gRPC predict response to dict
              if isinstance(response, ModelInferResponse):
                  return InferResponse.from_grpc(response).to_rest()
              elif isinstance(response, InferResponse):
                  return response.to_rest()
      return response
  
imports: import logging
  import pathlib
  from enum import Enum
  from typing import Dict, Union
  import grpc
  import inference_pb2_grpc
  import kserve
  from gprc_utils import from_ts_grpc, to_ts_grpc
  from inference_pb2 import PredictionResponse
  from kserve.errors import ModelMissingError
  from kserve.model import Model
  from kserve.protocol.grpc.grpc_predict_v2_pb2 import ModelInferRequest, ModelInferResponse
  from kserve.protocol.infer_type import InferRequest, InferResponse
  from kserve.storage import Storage
label_desc: Use image node_id 3 for calling the TorchserveModel obj's underlying member method code with example usage: obj.postprocess(response, headers) and returns: response, response, InferResponse, response, response, from_ts_grpc