Skip to content

feature: Allow users to send custom attributes to the model endpoint #2198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/sagemaker/clarify.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __init__(
accept_type=None,
content_type=None,
content_template=None,
custom_attributes=None,
):
"""Initializes a configuration of a model and the endpoint to be created for it.

Expand All @@ -141,6 +142,15 @@ def __init__(
"application/jsonlines". The template should have one and only one placeholder
$features which will be replaced by a features list for to form the model inference
input.
custom_attributes (str): Provides additional information about a request for an
inference submitted to a model hosted at an Amazon SageMaker endpoint. The
information is an opaque value that is forwarded verbatim. You could use this
value, for example, to provide an ID that you can use to track a request or to
provide other metadata that a service endpoint was programmed to process. The value
must consist of no more than 1024 visible US-ASCII characters as specified in
Section 3.3.6. Field Value Components (
https://tools.ietf.org/html/rfc7230#section-3.2.6) of the Hypertext Transfer
Protocol (HTTP/1.1).
"""
self.predictor_config = {
"model_name": model_name,
Expand Down Expand Up @@ -169,6 +179,9 @@ def __init__(
)
self.predictor_config["content_template"] = content_template

if custom_attributes is not None:
self.predictor_config["custom_attributes"] = custom_attributes

def get_predictor_config(self):
"""Returns part of the predictor dictionary of the analysis config."""
return copy.deepcopy(self.predictor_config)
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/test_clarify.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,22 @@ def test_model_config():
instance_count = 1
accept_type = "text/csv"
content_type = "application/jsonlines"
custom_attributes = "c000b4f9-df62-4c85-a0bf-7c525f9104a4"
model_config = ModelConfig(
model_name=model_name,
instance_type=instance_type,
instance_count=instance_count,
accept_type=accept_type,
content_type=content_type,
custom_attributes=custom_attributes,
)
expected_config = {
"model_name": model_name,
"instance_type": instance_type,
"initial_instance_count": instance_count,
"accept_type": accept_type,
"content_type": content_type,
"custom_attributes": custom_attributes,
}
assert expected_config == model_config.get_predictor_config()

Expand Down