Reputation: 542
I was evaluating what is needed to write your own Estimator in Sagemaker. I was following this example here and it's well explained and quite simple.
My question is regarding the inference here. I see an example in which we can feed the invocations endpoint a CSV. What if I want to just post a string or even individual parameters? What's the best practise for that? I see there is a condition like:
if flask.request.content_type == "text/csv":
Should we add more like those to support different formats or should we create a new endpoint?
Upvotes: 0
Views: 371
Reputation: 14689
You need to add support for more content types.
Since you would like to pass a string or a parameter, I suggest you add support for "application/json" MIME media type (What is the correct JSON content type?). Then your users will call the API with a Json that you can parse and extract parameters from in the backend.
For example, if you have two parameters age
and gender
you want to pass to your model. You can put them in the following Json datastructure:
{
"age": ...,
"gender": ...
}
Then add support for loading the Json and extracting the parameters in the backend as follows:
if flask.request.content_type == "application/json":
data = flask.request.data.decode("utf-8")
data = json.loads(data)
parameter1 = data['age']
parameter2 = data['gender']
...
Upvotes: 1