Shortcuts

Source code for ts.torch_handler.request_envelope.base

"""
Base class for all RequestEnvelope.

A request envelope reformats the inputs/outputs of a call to a handler.
It translates from formats specific to a model orchestrator like Seldon or
KServe to a set of flat Python items, and vice versa.
"""

from abc import ABC, abstractmethod


[docs]class BaseEnvelope(ABC): """ Interface for all envelopes. Derive from this class, replacing the abstract methods """ def __init__(self, handle_fn): self._handle_fn = handle_fn self.context = None
[docs] def handle(self, data, context): """ The Input Requests and Response are handled here. """ self.context = context if data: data = self.parse_input(data) results = self._handle_fn(data, context) if results: results = self.format_output(results) return results
[docs] @abstractmethod def parse_input(self, data): pass
[docs] @abstractmethod def format_output(self, data): pass

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources