code: def to_ts_grpc(
      data: Union[ModelInferRequest, InferRequest]
  ) -> PredictionsRequest:
      """Converts the InferRequest object to Torchserve gRPC PredictionsRequest message"""
      if isinstance(data, InferRequest):
          data = data.to_grpc()
      infer_request = {}
      model_name = data.model_name
      infer_inputs = [
          dict(
              name=input_tensor.name,
              shape=list(input_tensor.shape),
              datatype=input_tensor.datatype,
              data=get_content(
                  input_tensor.datatype, input_tensor.contents
              ),
          )
          for input_tensor in data.inputs
      ]
      infer_request["id"] = data.id
      infer_request["inputs"] = infer_inputs
      ts_grpc_input = {
          "data": json.dumps(infer_request).encode("utf-8")
      }
      return PredictionsRequest(
          model_name=model_name, input=ts_grpc_input
      )
  
file_path: serve/kubernetes/kserve/kserve_wrapper/gprc_utils.py
imports: import base64
  import json
  from typing import Union
  from inference_pb2 import PredictionResponse, PredictionsRequest
  from kserve.errors import InvalidInput
  from kserve.protocol.grpc.grpc_predict_v2_pb2 import InferTensorContents, ModelInferRequest
  from kserve.protocol.infer_type import InferOutput, InferRequest, InferResponse
label_desc: Use image node_id 2 for calling a global function with example usage: to_ts_grpc(data) and returns: PredictionsRequest