Skip to content

Commit 95ef81f

Browse files
committed
Add PredictorBase
1 parent df4af48 commit 95ef81f

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/sagemaker/predictor.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"""Placeholder docstring"""
1414
from __future__ import print_function, absolute_import
1515

16+
import abc
17+
from typing import Any, Tuple
18+
1619
from sagemaker.deprecations import (
1720
deprecated_class,
1821
deprecated_deserialize,
@@ -51,7 +54,29 @@
5154
from sagemaker.lineage.context import EndpointContext
5255

5356

54-
class Predictor(object):
57+
class PredictorBase(abc.ABC):
58+
"""An object that encapsulates a deployed model."""
59+
60+
@abc.abstractmethod
61+
def predict(self, *args, **kwargs) -> Any:
62+
"""Perform inference on the provided data and return a prediction."""
63+
64+
@abc.abstractmethod
65+
def destroy(self, *args, **kwargs) -> None:
66+
"""Destroy resources associated with this predictor."""
67+
68+
@property
69+
@abc.abstractmethod
70+
def content_type(self) -> str:
71+
"""The MIME type of the data sent to the inference server."""
72+
73+
@property
74+
@abc.abstractmethod
75+
def accept(self) -> Tuple[str]:
76+
"""The content type(s) that are expected from the inference server."""
77+
78+
79+
class Predictor(PredictorBase):
5580
"""Make prediction requests to an Amazon SageMaker endpoint."""
5681

5782
def __init__(
@@ -305,6 +330,8 @@ def delete_endpoint(self, delete_endpoint_config=True):
305330

306331
self.sagemaker_session.delete_endpoint(self.endpoint_name)
307332

333+
destroy = delete_endpoint
334+
308335
def delete_model(self):
309336
"""Deletes the Amazon SageMaker models backing this predictor."""
310337
request_failed = False

0 commit comments

Comments
 (0)