

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 `endpoints` 命令管理推論端點
<a name="machine-learning-api-endpoints"></a>

您可以使用 Neptune ML `endpoints` 命令來建立推論端點、檢查其狀態、將其刪除，或列出現有的推論端點。

## 使用 Neptune ML `endpoints` 命令建立推論端點
<a name="machine-learning-api-endpoints-create-job"></a>

如下 Neptune ML `endpoints` 命令可從訓練工作所建立的模型建立推論端點：

------
#### [ AWS CLI ]

```
aws neptunedata create-ml-endpoint \
  --endpoint-url https://your-neptune-endpoint:port \
  --id "(a unique ID for the new endpoint)" \
  --ml-model-training-job-id "(the model-training job-id of a completed job)"
```

如需詳細資訊，請參閱《 AWS CLI 命令參考》中的 [create-ml-endpoint](https://docs.aws.amazon.com/cli/latest/reference/neptunedata/create-ml-endpoint.html)。

------
#### [ SDK ]

```
import boto3
from botocore.config import Config

client = boto3.client(
    'neptunedata',
    endpoint_url='https://your-neptune-endpoint:port',
    config=Config(read_timeout=None, retries={'total_max_attempts': 1})
)

response = client.create_ml_endpoint(
    id='(a unique ID for the new endpoint)',
    mlModelTrainingJobId='(the model-training job-id of a completed job)'
)

print(response)
```

------
#### [ awscurl ]

```
awscurl https://your-neptune-endpoint:port/ml/endpoints \
  --region us-east-1 \
  --service neptune-db \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
        "id" : "(a unique ID for the new endpoint)",
        "mlModelTrainingJobId": "(the model-training job-id of a completed job)"
      }'
```

**注意**  
此範例假設您的 AWS 登入資料已在您的環境中設定。將 *us-east-1* 取代為 Neptune 叢集的區域。

------
#### [ curl ]

```
curl \
  -X POST https://your-neptune-endpoint:port/ml/endpoints \
  -H 'Content-Type: application/json' \
  -d '{
        "id" : "(a unique ID for the new endpoint)",
        "mlModelTrainingJobId": "(the model-training job-id of a completed job)"
      }'
```

------

如下 Neptune ML `endpoints` 命令可從訓練工作所建立的模型更新現有的推論端點：

------
#### [ AWS CLI ]

```
aws neptunedata create-ml-endpoint \
  --endpoint-url https://your-neptune-endpoint:port \
  --id "(a unique ID for the new endpoint)" \
  --update \
  --ml-model-training-job-id "(the model-training job-id of a completed job)"
```

如需詳細資訊，請參閱《 AWS CLI 命令參考》中的 [create-ml-endpoint](https://docs.aws.amazon.com/cli/latest/reference/neptunedata/create-ml-endpoint.html)。

------
#### [ SDK ]

```
import boto3
from botocore.config import Config

client = boto3.client(
    'neptunedata',
    endpoint_url='https://your-neptune-endpoint:port',
    config=Config(read_timeout=None, retries={'total_max_attempts': 1})
)

response = client.create_ml_endpoint(
    id='(a unique ID for the new endpoint)',
    update=True,
    mlModelTrainingJobId='(the model-training job-id of a completed job)'
)

print(response)
```

------
#### [ awscurl ]

```
awscurl https://your-neptune-endpoint:port/ml/endpoints \
  --region us-east-1 \
  --service neptune-db \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
        "id" : "(a unique ID for the new endpoint)",
        "update" : "true",
        "mlModelTrainingJobId": "(the model-training job-id of a completed job)"
      }'
```

**注意**  
此範例假設您的 AWS 登入資料已在您的環境中設定。將 *us-east-1* 取代為 Neptune 叢集的區域。

------
#### [ curl ]

```
curl \
  -X POST https://your-neptune-endpoint:port/ml/endpoints \
  -H 'Content-Type: application/json' \
  -d '{
        "id" : "(a unique ID for the new endpoint)",
        "update" : "true",
        "mlModelTrainingJobId": "(the model-training job-id of a completed job)"
      }'
```

------

如下 Neptune ML `endpoints` 命令可從模型轉換工作所建立的模型建立推論端點：

------
#### [ AWS CLI ]

```
aws neptunedata create-ml-endpoint \
  --endpoint-url https://your-neptune-endpoint:port \
  --id "(a unique ID for the new endpoint)" \
  --ml-model-transform-job-id "(the model-transform job-id of a completed job)"
```

如需詳細資訊，請參閱《 AWS CLI 命令參考》中的 [create-ml-endpoint](https://docs.aws.amazon.com/cli/latest/reference/neptunedata/create-ml-endpoint.html)。

------
#### [ SDK ]

```
import boto3
from botocore.config import Config

client = boto3.client(
    'neptunedata',
    endpoint_url='https://your-neptune-endpoint:port',
    config=Config(read_timeout=None, retries={'total_max_attempts': 1})
)

response = client.create_ml_endpoint(
    id='(a unique ID for the new endpoint)',
    mlModelTransformJobId='(the model-transform job-id of a completed job)'
)

print(response)
```

------
#### [ awscurl ]

```
awscurl https://your-neptune-endpoint:port/ml/endpoints \
  --region us-east-1 \
  --service neptune-db \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
        "id" : "(a unique ID for the new endpoint)",
        "mlModelTransformJobId": "(the model-transform job-id of a completed job)"
      }'
```

**注意**  
此範例假設您的 AWS 登入資料已在您的環境中設定。將 *us-east-1* 取代為 Neptune 叢集的區域。

------
#### [ curl ]

```
curl \
  -X POST https://your-neptune-endpoint:port/ml/endpoints \
  -H 'Content-Type: application/json' \
  -d '{
        "id" : "(a unique ID for the new endpoint)",
        "mlModelTransformJobId": "(the model-transform job-id of a completed job)"
      }'
```

------

如下 Neptune ML `endpoints` 命令可從模型轉換工作所建立的模型更新現有的推論端點：

------
#### [ AWS CLI ]

```
aws neptunedata create-ml-endpoint \
  --endpoint-url https://your-neptune-endpoint:port \
  --id "(a unique ID for the new endpoint)" \
  --update \
  --ml-model-transform-job-id "(the model-transform job-id of a completed job)"
```

如需詳細資訊，請參閱《 AWS CLI 命令參考》中的 [create-ml-endpoint](https://docs.aws.amazon.com/cli/latest/reference/neptunedata/create-ml-endpoint.html)。

------
#### [ SDK ]

```
import boto3
from botocore.config import Config

client = boto3.client(
    'neptunedata',
    endpoint_url='https://your-neptune-endpoint:port',
    config=Config(read_timeout=None, retries={'total_max_attempts': 1})
)

response = client.create_ml_endpoint(
    id='(a unique ID for the new endpoint)',
    update=True,
    mlModelTransformJobId='(the model-transform job-id of a completed job)'
)

print(response)
```

------
#### [ awscurl ]

```
awscurl https://your-neptune-endpoint:port/ml/endpoints \
  --region us-east-1 \
  --service neptune-db \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
        "id" : "(a unique ID for the new endpoint)",
        "update" : "true",
        "mlModelTransformJobId": "(the model-transform job-id of a completed job)"
      }'
```

**注意**  
此範例假設您的 AWS 登入資料已在您的環境中設定。將 *us-east-1* 取代為 Neptune 叢集的區域。

------
#### [ curl ]

```
curl \
  -X POST https://your-neptune-endpoint:port/ml/endpoints \
  -H 'Content-Type: application/json' \
  -d '{
        "id" : "(a unique ID for the new endpoint)",
        "update" : "true",
        "mlModelTransformJobId": "(the model-transform job-id of a completed job)"
      }'
```

------

**用於建立 `endpoints` 推論端點的參數**
+ **`id`** – (*選用*) 新推論端點的唯一識別符。

  *類型*：字串 *預設值*：自動產生的時間戳記名稱。
+ **`mlModelTrainingJobId`** – 已完成模型訓練工作的工作 ID，該工作已建立推論端點將指向的模型。

  *類型*：字串

  *注意*：您必須提供 `mlModelTrainingJobId` 或 `mlModelTransformJobId`。
+ **`mlModelTransformJobId`** – 已完成模型轉換工作的工作 ID。

  *類型*：字串

  *注意*：您必須提供 `mlModelTrainingJobId` 或 `mlModelTransformJobId`。
+ **`update`** – (*選用*) 如果存在，此參數指示這是更新請求。

  *類型*：布林值。*預設*：`false`

  *注意*：您必須提供 `mlModelTrainingJobId` 或 `mlModelTransformJobId`。
+ **`neptuneIamRoleArn`**   – (*選用*) IAM 角色的 ARN，提供對 SageMaker AI 和 Amazon S3 資源的 Neptune 存取權。

  *類型*：字串 *注意*：這必須列示在您的資料庫叢集參數群組中，否則會擲回錯誤。
+ **`modelName`** – (*選用*) 用於訓練的模型類型。根據預設，ML 模型會是自動以資料處理中使用的 `modelType` 為基礎，但您可以在這裡指定不同的模型類型。

  *類型*：字串 *預設值*：`rgcn` 用於異質圖和 `kge` 用於知識圖譜。*有效值*：若為異質圖：`rgcn`。若為知識圖譜：`kge`、`transe`、`distmult` 或 `rotate`。
+ **`instanceType`** – (*選用*) 用於線上服務的 ML 執行個體類型。

  *類型*：字串 *預設*︰`ml.m5.xlarge`。

  *注意*：為推論端點選擇 ML 執行個體，取決於任務類型、圖形大小以及您的預算。請參閱 [為推論端點選取執行個體](machine-learning-on-graphs-instance-selection.md#machine-learning-on-graphs-inference-endpoint-instance-size)。
+ **`instanceCount`** – (*選用*) 要部署到端點進行預測的 Amazon EC2 執行個體數量下限。

  *類型*：整數。*預設*︰`1`。
+ **`volumeEncryptionKMSKey`**   – (*選用*) SageMaker AI 用來加密連接至執行端點之 ML 運算執行個體之儲存磁碟區上的資料 AWS Key Management Service ()AWS KMS金鑰。

  *類型*：字串 *預設值*：*none*。

## 使用 Neptune ML `endpoints` 命令取得推論端點的狀態
<a name="machine-learning-api-endpoints-get-endpoint-status"></a>

執行個體端點狀態的範例 Neptune ML `endpoints` 命令如下所示：

------
#### [ AWS CLI ]

```
aws neptunedata get-ml-endpoint \
  --endpoint-url https://your-neptune-endpoint:port \
  --id "(the inference endpoint ID)"
```

如需詳細資訊，請參閱《 AWS CLI 命令參考》中的 [get-ml-endpoint](https://docs.aws.amazon.com/cli/latest/reference/neptunedata/get-ml-endpoint.html)。

------
#### [ SDK ]

```
import boto3
from botocore.config import Config

client = boto3.client(
    'neptunedata',
    endpoint_url='https://your-neptune-endpoint:port',
    config=Config(read_timeout=None, retries={'total_max_attempts': 1})
)

response = client.get_ml_endpoint(
    id='(the inference endpoint ID)'
)

print(response)
```

------
#### [ awscurl ]

```
awscurl https://your-neptune-endpoint:port/ml/endpoints/(the inference endpoint ID) \
  --region us-east-1 \
  --service neptune-db \
  -X GET
```

**注意**  
此範例假設您的 AWS 登入資料已在您的環境中設定。將 *us-east-1* 取代為 Neptune 叢集的區域。

------
#### [ curl ]

```
curl -s \
  "https://your-neptune-endpoint:port/ml/endpoints/(the inference endpoint ID)" \
  | python -m json.tool
```

------

**`endpoints` 執行個體-端點狀態的參數**
+ **`id`** – (*必要*) 推論端點的唯一識別符。

  *類型*：字串
+ **`neptuneIamRoleArn`**   – (*選用*) IAM 角色的 ARN，提供對 SageMaker AI 和 Amazon S3 資源的 Neptune 存取權。

  *類型*：字串 *注意*：這必須列示在您的資料庫叢集參數群組中，否則會擲回錯誤。

## 使用 Neptune ML `endpoints` 命令刪除執行個體端點
<a name="machine-learning-api-endpoints-delete-endpoint"></a>

用於刪除執行個體端點的範例 Neptune ML `endpoints` 命令如下所示：

------
#### [ AWS CLI ]

```
aws neptunedata delete-ml-endpoint \
  --endpoint-url https://your-neptune-endpoint:port \
  --id "(the inference endpoint ID)"
```

同時清除相關成品：

```
aws neptunedata delete-ml-endpoint \
  --endpoint-url https://your-neptune-endpoint:port \
  --id "(the inference endpoint ID)" \
  --clean
```

如需詳細資訊，請參閱《 AWS CLI 命令參考》中的 [delete-ml-endpoint](https://docs.aws.amazon.com/cli/latest/reference/neptunedata/delete-ml-endpoint.html)。

------
#### [ SDK ]

```
import boto3
from botocore.config import Config

client = boto3.client(
    'neptunedata',
    endpoint_url='https://your-neptune-endpoint:port',
    config=Config(read_timeout=None, retries={'total_max_attempts': 1})
)

response = client.delete_ml_endpoint(
    id='(the inference endpoint ID)',
    clean=True
)

print(response)
```

------
#### [ awscurl ]

```
awscurl https://your-neptune-endpoint:port/ml/endpoints/(the inference endpoint ID) \
  --region us-east-1 \
  --service neptune-db \
  -X DELETE
```

同時清除相關成品：

```
awscurl "https://your-neptune-endpoint:port/ml/endpoints/(the inference endpoint ID)?clean=true" \
  --region us-east-1 \
  --service neptune-db \
  -X DELETE
```

**注意**  
此範例假設您的 AWS 登入資料已在您的環境中設定。將 *us-east-1* 取代為 Neptune 叢集的區域。

------
#### [ curl ]

```
curl -s \
  -X DELETE "https://your-neptune-endpoint:port/ml/endpoints/(the inference endpoint ID)"
```

或如下所示：

```
curl -s \
  -X DELETE "https://your-neptune-endpoint:port/ml/endpoints/(the inference endpoint ID)?clean=true"
```

------

**`endpoints` 刪除推論端點的參數**
+ **`id`** – (*必要*) 推論端點的唯一識別符。

  *類型*：字串
+ **`neptuneIamRoleArn`**   – (*選用*) IAM 角色的 ARN，提供對 SageMaker AI 和 Amazon S3 資源的 Neptune 存取權。

  *類型*：字串 *注意*：這必須列示在您的資料庫叢集參數群組中，否則會擲回錯誤。
+ **`clean`** – (*選用*) 指示也應刪除與此端點相關的所有成品。

  *類型*：布林值。*預設*︰`FALSE`。

## 使用 Neptune ML `endpoints` 命令列出推論端點
<a name="machine-learning-api-endpoints-list-endpoints"></a>

用於列出推論端點的 Neptune ML `endpoints` 命令如下所示：

------
#### [ AWS CLI ]

```
aws neptunedata list-ml-endpoints \
  --endpoint-url https://your-neptune-endpoint:port
```

若要限制結果數量：

```
aws neptunedata list-ml-endpoints \
  --endpoint-url https://your-neptune-endpoint:port \
  --max-items 3
```

如需詳細資訊，請參閱《 AWS CLI 命令參考》中的 [list-ml-endpoints](https://docs.aws.amazon.com/cli/latest/reference/neptunedata/list-ml-endpoints.html)。

------
#### [ SDK ]

```
import boto3
from botocore.config import Config

client = boto3.client(
    'neptunedata',
    endpoint_url='https://your-neptune-endpoint:port',
    config=Config(read_timeout=None, retries={'total_max_attempts': 1})
)

response = client.list_ml_endpoints(
    maxItems=3
)

print(response)
```

------
#### [ awscurl ]

```
awscurl https://your-neptune-endpoint:port/ml/endpoints \
  --region us-east-1 \
  --service neptune-db \
  -X GET
```

若要限制結果數量：

```
awscurl "https://your-neptune-endpoint:port/ml/endpoints?maxItems=3" \
  --region us-east-1 \
  --service neptune-db \
  -X GET
```

**注意**  
此範例假設您的 AWS 登入資料已在您的環境中設定。將 *us-east-1* 取代為 Neptune 叢集的區域。

------
#### [ curl ]

```
curl -s "https://your-neptune-endpoint:port/ml/endpoints" \
  | python -m json.tool
```

或如下所示：

```
curl -s "https://your-neptune-endpoint:port/ml/endpoints?maxItems=3" \
  | python -m json.tool
```

------

**`dataprocessing` 列出推論端點的參數**
+ **`maxItems`** – (*選用*) 要傳回的項目數上限。

  *類型*：整數。*預設*︰`10`。*允許的最大值*：`1024`。
+ **`neptuneIamRoleArn`**   – (*選用*) IAM 角色的 ARN，提供對 SageMaker AI 和 Amazon S3 資源的 Neptune 存取權。

  *類型*：字串 *注意*：這必須列示在您的資料庫叢集參數群組中，否則會擲回錯誤。