Skip to content

Commit 7d459ea

Browse files
ignacioalvarolopez
authored andcommitted
improve docs
1 parent 88d63eb commit 7d459ea

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

doc/source/user/v2-api.rst

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,33 @@ Sometimes it is useful to return something different than a JSON file. For such
248248
cases, you can define an additional argument ``accept`` defining the content
249249
types that you are able to return as follows::
250250

251-
def get_predict_args():
251+
def get_predict_args():
252252
return {
253-
"accept": fields.Str(
254-
description="Media type(s) that is/are acceptable for the response.",
255-
validate=validate.OneOf(["text/plain"]),
253+
'accept': fields.Str(description="Media type(s) that is/are acceptable for the response.",
254+
missing='application/zip',
255+
validate=validate.OneOf(['application/zip', 'image/png', 'application/json']))
256256
}
257257

258-
Consequently, the predict calls will receive an ``accept`` argument containing
259-
the content type requested by the user. Find `here <https://www.iana.org/assignments/media-types/media-types.xhtml>`_
260-
a comprehensive list of possible content types.
258+
Find `here <https://www.iana.org/assignments/media-types/media-types.xhtml>`_ a comprehensive list of possible
259+
content types. Then the predict function will have to return the raw bytes of a file according to the user selection.
260+
For example::
261+
262+
263+
def predict(**args):
264+
# Run your prediction
265+
266+
# Return file according to user selection
267+
if args['accept'] == 'image/png':
268+
return open(img_path, 'rb')
269+
270+
elif args['accept'] == 'application/json':
271+
return {'some': 'json'}
272+
273+
elif args['accept'] == 'application/zip':
274+
return open(zip_path, 'rb')
275+
276+
If you want to return several content types at the same time (let's say a JSON and an image), the easiest way it to
277+
return a zip file with all the files.
261278

262279
Using classes
263280
-------------

0 commit comments

Comments
 (0)