class_docstr: Implementation. Captures batches in KServe v2 protocol format, returns
  also in FServing v2 protocol format.
class_docstr_tok: ["Implementation",".","Captures","batches","in","KServe","v2","protocol","format",",","returns","also","in","FServing","v2","protocol","format","."]
docstr: Translates Torchserve output KServe v2 response format.
  
  Parameters:
  data (list): Torchserve response for handler.
  
  Returns: KServe v2 response json.
  {
    "id": "f0222600-353f-47df-8d9d-c96d96fa894e",
    "model_name": "bert",
    "model_version": "1",
    "outputs": [{
      "name": "input-0",
      "shape": [1],
      "datatype": "INT64",
      "data": [2]
    }]
  }
docstr_tok: ["Translates","Torchserve","output","KServe","v2","response","format",".","Parameters",":","data","(","list",")",":","Torchserve","response","for","handler",".","Returns",":","KServe","v2","response","json",".","{","``","id","''",":","``","f0222600-353f-47df-8d9d-c96d96fa894e","''",",","``","model_name","''",":","``","bert","''",",","``","model_version","''",":","``","1","''",",","``","outputs","''",":","[","{","``","name","''",":","``","input-0","''",",","``","shape","''",":","[","1","]",",","``","datatype","''",":","``","INT64","''",",","``","data","''",":","[","2","]","}","]","}"]
code: def format_output(self, data):
      """Translates Torchserve output KServe v2 response format.
  
      Parameters:
      data (list): Torchserve response for handler.
  
      Returns: KServe v2 response json.
      {
        "id": "f0222600-353f-47df-8d9d-c96d96fa894e",
        "model_name": "bert",
        "model_version": "1",
        "outputs": [{
          "name": "input-0",
          "shape": [1],
          "datatype": "INT64",
          "data": [2]
        }]
      }
  
      """
      logger.debug("The Response of KServe v2 format %s", data)
      response = {}
      if hasattr(self.context, "input_request_id"):
          response["id"] = getattr(self.context, "input_request_id")
          delattr(self.context, "input_request_id")
      else:
          response["id"] = self.context.get_request_id(0)
      # TODO: Add parameters support
      # if hasattr(self.context, "input_parameters"):
      #     response["parameters"] = getattr(self.context, "input_parameters")
      #     delattr(self.context, "input_parameters")
      response["model_name"] = self.context.manifest.get("model").get(
          "modelName"
      )
      response["model_version"] = self.context.manifest.get(
          "model"
      ).get("modelVersion")
      response["outputs"] = self._batch_to_json(data)
      return [response]
  
file_path: serve/ts/torch_handler/request_envelope/kservev2.py
imports: import json
  import logging
  import numpy
  from .base import BaseEnvelope
label_desc: Use image node_id 4 for calling the KServev2Envelope obj's underlying member method code with example usage: obj.format_output(data) and returns: list