

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# AWS CLI v1 示例
<a name="clarify-processing-job-data-format-tabular-precheck-cli-v1-examples"></a>

上一节中的示例适用于 AWS CLI v2。以下发送到端点的请求示例和来自端点的响应示例使用 AWS CLI v1。

## CSV 格式的端点请求和响应
<a name="clarify-processing-job-data-format-tabular-precheck-csv"></a>

在以下代码示例中，请求由一条记录组成，响应是其概率值。

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-sagemaker-xgboost-model \
  --content-type text/csv \
  --accept text/csv \
  --body '1,2,3,4' \
  /dev/stderr 1>/dev/null
```

在前面的代码示例中，响应输出如下。

```
0.6
```

在以下代码示例中，请求由两条记录组成，响应包括其概率，这些概率用逗号分隔。

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-sagemaker-xgboost-model \
  --content-type text/csv \
  --accept text/csv \
  --body $'1,2,3,4\n5,6,7,8' \
  /dev/stderr 1>/dev/null
```

在前面的代码示例中，`--body` 中的 `$'content'` 表达式告诉命令将内容中的 `'\n'` 解释为换行符。响应输出如下。

```
0.6,0.3
```

在以下代码示例中，请求由两条记录组成，响应包括其概率，这些概率用换行符分隔。

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-csv-1 \
  --content-type text/csv \
  --accept text/csv \
  --body $'1,2,3,4\n5,6,7,8' \
  /dev/stderr 1>/dev/null
```

在前面的代码示例中，响应输出如下。

```
0.6
0.3
```

在以下代码示例中，请求由一条记录组成，响应是来自包含三个类的多类模型的概率值。

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-csv-1 \
  --content-type text/csv \
  --accept text/csv \
  --body '1,2,3,4' \
  /dev/stderr 1>/dev/null
```

在前面的代码示例中，响应输出如下。

```
0.1,0.6,0.3
```

在以下代码示例中，请求由两条记录组成，响应包括来自包含三个类的多类模型的概率值。

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-csv-1 \
  --content-type text/csv \
  --accept text/csv \
  --body $'1,2,3,4\n5,6,7,8' \
  /dev/stderr 1>/dev/null
```

在前面的代码示例中，响应输出如下。

```
0.1,0.6,0.3
0.2,0.5,0.3
```

在以下代码示例中，请求由两条记录组成，响应包括预测标签和概率。

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-csv-2 \
  --content-type text/csv \
  --accept text/csv \
  --body $'1,2,3,4\n5,6,7,8' \
  /dev/stderr 1>/dev/null
```

在前面的代码示例中，响应输出如下。

```
1,0.6
0,0.3
```

在以下代码示例中，请求由两条记录组成，响应包括标签标题和概率。

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-csv-3 \
  --content-type text/csv \
  --accept text/csv \
  --body $'1,2,3,4\n5,6,7,8' \
  /dev/stderr 1>/dev/null
```

在前面的代码示例中，响应输出如下。

```
"['cat','dog','fish']","[0.1,0.6,0.3]"
"['cat','dog','fish']","[0.2,0.5,0.3]"
```

## JSON 行格式的端点请求和响应
<a name="clarify-processing-job-data-format-tabular-precheck-jsonlines"></a>

在以下代码示例中，请求由一条记录组成，响应是其概率值。

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-jsonlines \
  --content-type application/jsonlines \
  --accept application/jsonlines \
  --body '{"features":["This is a good product",5]}' \
  /dev/stderr 1>/dev/null
```

在前面的代码示例中，响应输出如下。

```
{"score":0.6}
```

在以下代码示例中，请求由两条记录组成，响应包括预测标签和概率。

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-jsonlines-2 \
  --content-type application/jsonlines \
  --accept application/jsonlines \
  --body $'{"features":[1,2,3,4]}\n{"features":[5,6,7,8]}' \
  /dev/stderr 1>/dev/null
```

在前面的代码示例中，响应输出如下。

```
{"predicted_label":1,"probability":0.6}
{"predicted_label":0,"probability":0.3}
```

在以下代码示例中，请求由两条记录组成，响应包括标签标题和概率。

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-jsonlines-3 \
  --content-type application/jsonlines \
  --accept application/jsonlines \
  --body $'{"data":{"features":[1,2,3,4]}}\n{"data":{"features":[5,6,7,8]}}' \
  /dev/stderr 1>/dev/null
```

在前面的代码示例中，响应输出如下。

```
{"predicted_labels":["cat","dog","fish"],"probabilities":[0.1,0.6,0.3]}
{"predicted_labels":["cat","dog","fish"],"probabilities":[0.2,0.5,0.3]}
```

## 混合格式的端点请求和响应
<a name="clarify-processing-job-data-format-tabular-precheck-diff"></a>

在以下代码示例中，请求采用 CSV 格式，响应采用 JSON 行格式。

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-csv-in-jsonlines-out \
  --content-type text/csv \
  --accept application/jsonlines \
  --body $'1,2,3,4\n5,6,7,8' \
  /dev/stderr 1>/dev/null
```

在前面的代码示例中，响应输出如下。

```
{"probability":0.6}
{"probability":0.3}
```

在以下代码示例中，请求采用 JSON 行格式，响应采用 CSV 格式。

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-jsonlines-in-csv-out \
  --content-type application/jsonlines \
  --accept text/csv \
  --body $'{"features":[1,2,3,4]}\n{"features":[5,6,7,8]}' \
  /dev/stderr 1>/dev/null
```

在前面的代码示例中，响应输出如下。

```
0.6
0.3
```

在以下代码示例中，请求采用 CSV 格式，响应采用 JSON 格式。

```
aws sagemaker-runtime invoke-endpoint \
  --endpoint-name test-endpoint-csv-in-jsonlines-out \
  --content-type text/csv \
  --accept application/jsonlines \
  --body $'1,2,3,4\n5,6,7,8' \
  /dev/stderr 1>/dev/null
```

在前面的代码示例中，响应输出如下。

```
{"predictions":[{"label":1,"score":0.6},{"label":0,"score":0.3}]}
```