@@ -52,13 +52,13 @@ def deserialize(self, stream, content_type):
52
52
@property
53
53
@abc .abstractmethod
54
54
def ACCEPT (self ):
55
- """The content type that is expected from the inference endpoint."""
55
+ """The content types that are expected from the inference endpoint."""
56
56
57
57
58
58
class StringDeserializer (BaseDeserializer ):
59
59
"""Deserialize data from an inference endpoint into a decoded string."""
60
60
61
- ACCEPT = "application/json"
61
+ ACCEPT = ( "application/json" ,)
62
62
63
63
def __init__ (self , encoding = "UTF-8" ):
64
64
"""Initialize the string encoding.
@@ -87,7 +87,7 @@ def deserialize(self, stream, content_type):
87
87
class BytesDeserializer (BaseDeserializer ):
88
88
"""Deserialize a stream of bytes into a bytes object."""
89
89
90
- ACCEPT = "*/*"
90
+ ACCEPT = ( "*/*" ,)
91
91
92
92
def deserialize (self , stream , content_type ):
93
93
"""Read a stream of bytes returned from an inference endpoint.
@@ -108,7 +108,7 @@ def deserialize(self, stream, content_type):
108
108
class CSVDeserializer (BaseDeserializer ):
109
109
"""Deserialize a stream of bytes into a list of lists."""
110
110
111
- ACCEPT = "text/csv"
111
+ ACCEPT = ( "text/csv" ,)
112
112
113
113
def __init__ (self , encoding = "utf-8" ):
114
114
"""Initialize the string encoding.
@@ -143,7 +143,7 @@ class StreamDeserializer(BaseDeserializer):
143
143
reading it.
144
144
"""
145
145
146
- ACCEPT = "*/*"
146
+ ACCEPT = ( "*/*" ,)
147
147
148
148
def deserialize (self , stream , content_type ):
149
149
"""Returns a stream of the response body and the MIME type of the data.
@@ -161,16 +161,17 @@ def deserialize(self, stream, content_type):
161
161
class NumpyDeserializer (BaseDeserializer ):
162
162
"""Deserialize a stream of data in the .npy format."""
163
163
164
- ACCEPT = "application/x-npy"
165
-
166
- def __init__ (self , dtype = None , allow_pickle = True ):
164
+ def __init__ (self , dtype = None , accept = "application/x-npy" , allow_pickle = True ):
167
165
"""Initialize the dtype and allow_pickle arguments.
168
166
169
167
Args:
170
168
dtype (str): The dtype of the data (default: None).
169
+ accept (str): The MIME type that is expected from the inference
170
+ endpoint (default: "application/x-npy").
171
171
allow_pickle (bool): Allow loading pickled object arrays (default: True).
172
172
"""
173
173
self .dtype = dtype
174
+ self .accept = accept
174
175
self .allow_pickle = allow_pickle
175
176
176
177
def deserialize (self , stream , content_type ):
@@ -197,11 +198,21 @@ def deserialize(self, stream, content_type):
197
198
198
199
raise ValueError ("%s cannot read content type %s." % (__class__ .__name__ , content_type ))
199
200
201
+ @property
202
+ def ACCEPT (self ):
203
+ """The content types that are expected from the inference endpoint.
204
+
205
+ To maintain backwards compatability with legacy images, the
206
+ NumpyDeserializer supports sending only one content type in the Accept
207
+ header.
208
+ """
209
+ return (self .accept ,)
210
+
200
211
201
212
class JSONDeserializer (BaseDeserializer ):
202
213
"""Deserialize JSON data from an inference endpoint into a Python object."""
203
214
204
- ACCEPT = "application/json"
215
+ ACCEPT = ( "application/json" ,)
205
216
206
217
def deserialize (self , stream , content_type ):
207
218
"""Deserialize JSON data from an inference endpoint into a Python object.
@@ -222,7 +233,7 @@ def deserialize(self, stream, content_type):
222
233
class PandasDeserializer (BaseDeserializer ):
223
234
"""Deserialize CSV or JSON data from an inference endpoint into a pandas dataframe."""
224
235
225
- ACCEPT = "text/csv"
236
+ ACCEPT = ( "text/csv" , "application/json" )
226
237
227
238
def deserialize (self , stream , content_type ):
228
239
"""Deserialize CSV or JSON data from an inference endpoint into a pandas
@@ -250,7 +261,7 @@ def deserialize(self, stream, content_type):
250
261
class JSONLinesDeserializer (BaseDeserializer ):
251
262
"""Deserialize JSON lines data from an inference endpoint."""
252
263
253
- ACCEPT = "application/jsonlines"
264
+ ACCEPT = ( "application/jsonlines" ,)
254
265
255
266
def deserialize (self , stream , content_type ):
256
267
"""Deserialize JSON lines data from an inference endpoint.
0 commit comments