You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/deployments/predictors.md
+18-6Lines changed: 18 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,11 +55,13 @@ class PythonPredictor:
55
55
"""
56
56
pass
57
57
58
-
defpredict(self, payload):
58
+
defpredict(self, payload, query_params, headers):
59
59
"""Called once per request. Preprocesses the request payload (if necessary), runs inference, and postprocesses the inference output (if necessary).
60
60
61
61
Args:
62
-
payload: The parsed JSON request payload.
62
+
payload: The request payload (see below for the possible payload types) (optional).
63
+
query_params: A dictionary of the query parameters used in the request (optional).
64
+
headers: A dictionary of the headers sent in the request (optional).
63
65
64
66
Returns:
65
67
Prediction or a batch of predictions.
@@ -69,6 +71,8 @@ class PythonPredictor:
69
71
70
72
For proper separation of concerns, it is recommended to use the constructor's `config` paramater for information such as from where to download the model and initialization files, or any configurable model parameters. You define `config` in your [API configuration](api-configuration.md), and it is passed through to your Predictor's constructor.
71
73
74
+
The `payload` parameter is parsed according to the `Content-Type` header in the request. For `Content-Type: application/json`, `payload` will be the parsed JSON body. For `Content-Type: multipart/form` or `Content-Type: application/x-www-form-urlencoded`, `payload` will be `starlette.datastructures.FormData` (key-value pairs where the value is a `string` for form data, or `starlette.datastructures.UploadFile` for file uploads, see [Starlette's documentation](https://www.starlette.io/requests/#request-files)). For all other `Content-Type` values, `payload` will the the raw `bytes` of the request body.
75
+
72
76
### Examples
73
77
74
78
<!-- CORTEX_VERSION_MINOR -->
@@ -173,11 +177,13 @@ class TensorFlowPredictor:
173
177
self.client = tensorflow_client
174
178
# Additional initialization may be done here
175
179
176
-
defpredict(self, payload):
180
+
defpredict(self, payload, query_params, headers):
177
181
"""Called once per request. Preprocesses the request payload (if necessary), runs inference (e.g. by calling self.client.predict(model_input)), and postprocesses the inference output (if necessary).
178
182
179
183
Args:
180
-
payload: The parsed JSON request payload.
184
+
payload: The request payload (see below for the possible payload types) (optional).
185
+
query_params: A dictionary of the query parameters used in the request (optional).
186
+
headers: A dictionary of the headers sent in the request (optional).
181
187
182
188
Returns:
183
189
Prediction or a batch of predictions.
@@ -190,6 +196,8 @@ Cortex provides a `tensorflow_client` to your Predictor's constructor. `tensorfl
190
196
191
197
For proper separation of concerns, it is recommended to use the constructor's `config` paramater for information such as configurable model parameters or download links for initialization files. You define `config` in your [API configuration](api-configuration.md), and it is passed through to your Predictor's constructor.
192
198
199
+
The `payload` parameter is parsed according to the `Content-Type` header in the request. For `Content-Type: application/json`, `payload` will be the parsed JSON body. For `Content-Type: multipart/form` or `Content-Type: application/x-www-form-urlencoded`, `payload` will be `starlette.datastructures.FormData` (key-value pairs where the value is a `string` for form data, or `starlette.datastructures.UploadFile` for file uploads, see [Starlette's documentation](https://www.starlette.io/requests/#request-files)). For all other `Content-Type` values, `payload` will the the raw `bytes` of the request body.
200
+
193
201
### Examples
194
202
195
203
<!-- CORTEX_VERSION_MINOR -->
@@ -249,11 +257,13 @@ class ONNXPredictor:
249
257
self.client = onnx_client
250
258
# Additional initialization may be done here
251
259
252
-
defpredict(self, payload):
260
+
defpredict(self, payload, query_params, headers):
253
261
"""Called once per request. Preprocesses the request payload (if necessary), runs inference (e.g. by calling self.client.predict(model_input)), and postprocesses the inference output (if necessary).
254
262
255
263
Args:
256
-
payload: The parsed JSON request payload.
264
+
payload: The request payload (see below for the possible payload types) (optional).
265
+
query_params: A dictionary of the query parameters used in the request (optional).
266
+
headers: A dictionary of the headers sent in the request (optional).
257
267
258
268
Returns:
259
269
Prediction or a batch of predictions.
@@ -266,6 +276,8 @@ Cortex provides an `onnx_client` to your Predictor's constructor. `onnx_client`
266
276
267
277
For proper separation of concerns, it is recommended to use the constructor's `config` paramater for information such as configurable model parameters or download links for initialization files. You define `config` in your [API configuration](api-configuration.md), and it is passed through to your Predictor's constructor.
268
278
279
+
The `payload` parameter is parsed according to the `Content-Type` header in the request. For `Content-Type: application/json`, `payload` will be the parsed JSON body. For `Content-Type: multipart/form` or `Content-Type: application/x-www-form-urlencoded`, `payload` will be `starlette.datastructures.FormData` (key-value pairs where the value is a `string` for form data, or `starlette.datastructures.UploadFile` for file uploads, see [Starlette's documentation](https://www.starlette.io/requests/#request-files)). For all other `Content-Type` values, `payload` will the the raw `bytes` of the request body.
0 commit comments