如要使用 gcloud CLI 或 Gemini Enterprise API 部署模型,請先建立公開端點。
如果您已有公開端點,可以略過這個步驟,直接使用 gcloud CLI 或 Gemini Enterprise API 部署模型。
本文說明如何建立新的公開端點。
建立專屬公開端點 (建議)
專屬公開端點的預設要求逾時時間為 10 分鐘。
在 Gemini Enterprise API 和 Python 適用的 Agent Platform SDK 中,您可以選擇加入含有新 inferenceTimeout 值的 clientConnectionConfig 物件,指定不同的要求逾時時間,如下列範例所示。逾時值上限為 3600 秒 (1 小時)。
Google Cloud 控制台
-
在 Google Cloud 控制台的「Agent Platform」部分,前往「Online prediction」頁面。
前往「線上預測」頁面 - 點選 「Create」(建立)。
- 在「New endpoint」(新增端點) 窗格中:
- 輸入「端點名稱」。
- 選取「標準」做為存取權類型。
- 勾選「啟用專屬 DNS」核取方塊。
- 按一下 [繼續]。
- 按一下 [完成]。
REST
使用任何要求資料之前,請先修改下列項目的值:
- LOCATION_ID:您的區域。
- PROJECT_ID: 您的 [專案 ID](/resource-manager/docs/creating-managing-projects#identifiers)。 。
- ENDPOINT_NAME:端點的顯示名稱。
- INFERENCE_TIMEOUT_SECS:(選用) 選用
inferenceTimeout欄位中的秒數。
HTTP 方法和網址:
POST https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/endpoints
JSON 要求主體:
{
"display_name": "ENDPOINT_NAME",
"dedicatedEndpointEnabled": true,
"clientConnectionConfig": {
"inferenceTimeout": {
"seconds": INFERENCE_TIMEOUT_SECS
}
}
}
請展開以下其中一個選項,以傳送要求:
您應該會收到如下的 JSON 回覆:
{
"name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/endpoints/ENDPOINT_ID/operations/OPERATION_ID",
"metadata": {
"@type": "type.googleapis.com/google.cloud.aiplatform.v1.CreateEndpointOperationMetadata",
"genericMetadata": {
"createTime": "2020-11-05T17:45:42.812656Z",
"updateTime": "2020-11-05T17:45:42.812656Z"
}
}
}
"done":
true 為止。
Python
在試用這個範例之前,請先按照「使用用戶端程式庫的 Agent Platform 快速入門導覽課程」中的 Python 設定說明操作。詳情請參閱 Agent Platform Python API 參考文件。
如要向 Agent Platform 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。
更改下列內容:
- PROJECT_ID:專案 ID。
- LOCATION_ID:您使用 Agent Platform 的區域。
- ENDPOINT_NAME:端點的顯示名稱。
- INFERENCE_TIMEOUT_SECS:(選用) 選用
inference_timeout值中的秒數。
from google.cloud import aiplatform
PROJECT_ID = "PROJECT_ID"
LOCATION = "LOCATION_ID"
ENDPOINT_NAME = "ENDPOINT_NAME"
INFERENCE_TIMEOUT_SECS = "INFERENCE_TIMEOUT_SECS"
aiplatform.init(
project=PROJECT_ID,
location=LOCATION,
api_endpoint=ENDPOINT_NAME,
)
dedicated_endpoint = aiplatform.Endpoint.create(
display_name=DISPLAY_NAME,
dedicated_endpoint_enabled=True,
sync=True,
inference_timeout=INFERENCE_TIMEOUT_SECS,
)
推論逾時設定
推論要求的預設逾時時間長度為 600 秒 (10 分鐘)。如果未在建立端點時明確指定推論逾時,系統就會套用這個逾時值。逾時值上限為一小時。
如要在建立端點時設定推論逾時,請使用 inference_timeout 參數,如下列程式碼片段所示:
timeout_endpoint = aiplatform.Endpoint.create(
display_name="dedicated-endpoint-with-timeout",
dedicated_endpoint_enabled=True,
inference_timeout=1800, # Unit: Seconds
)
端點建立後,可以使用 EndpointService.UpdateEndpointLongRunning 方法修改推論逾時設定。「EndpointService.UpdateEndpoint」方法不支援這項修改。
要求/回應記錄
要求/回應記錄功能會擷取 API 互動。不過,為遵守 BigQuery 限制,記錄檔會排除大小超過 10 MB 的酬載。
如要在建立端點時啟用及設定要求/回應記錄,請使用下列參數,如後續程式碼片段所示:
logging_endpoint = aiplatform.Endpoint.create(
display_name="dedicated-endpoint-with-logging",
dedicated_endpoint_enabled=True,
enable_request_response_logging=True,
request_response_logging_sampling_rate=1.0, # Default: 0.0
request_response_logging_bq_destination_table="bq://test_logging",
# If not set, a new BigQuery table will be created with the name:
# bq://{project_id}.logging_{endpoint_display_name}_{endpoint_id}.request_response_logging
)
端點建立後,可以使用 EndpointService.UpdateEndpointLongRunning 方法修改要求/回應記錄設定。EndpointService.UpdateEndpoint 方法不支援這項修改。
建立共用的公開端點
Google Cloud 控制台
-
在 Google Cloud 控制台的「Agent Platform」部分,前往「Online prediction」頁面。
前往「線上預測」頁面 - 點選 「Create」(建立)。
- 在「New endpoint」(新增端點) 窗格中:
- 輸入「端點名稱」。
- 選取「標準」做為存取權類型。
- 按一下 [繼續]。
- 按一下 [完成]。
gcloud
下列範例使用 gcloud ai endpoints create 指令:
gcloud ai endpoints create \
--region=LOCATION_ID \
--display-name=ENDPOINT_NAME
更改下列內容:
- LOCATION_ID:您使用 Agent Platform 的區域。
- ENDPOINT_NAME:端點的顯示名稱。
Google Cloud CLI 工具可能需要幾秒鐘才能建立端點。
REST
使用任何要求資料之前,請先修改下列項目的值:
- LOCATION_ID:您的區域。
- PROJECT_ID: 您的 [專案 ID](/resource-manager/docs/creating-managing-projects#identifiers)。 。
- ENDPOINT_NAME:端點的顯示名稱。
HTTP 方法和網址:
POST https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/endpoints
JSON 要求主體:
{
"display_name": "ENDPOINT_NAME"
}
請展開以下其中一個選項,以傳送要求:
您應該會收到如下的 JSON 回覆:
{
"name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/endpoints/ENDPOINT_ID/operations/OPERATION_ID",
"metadata": {
"@type": "type.googleapis.com/google.cloud.aiplatform.v1.CreateEndpointOperationMetadata",
"genericMetadata": {
"createTime": "2020-11-05T17:45:42.812656Z",
"updateTime": "2020-11-05T17:45:42.812656Z"
}
}
}
"done":
true 為止。
Terraform
下列範例使用 google_vertex_ai_endpoint Terraform 資源建立端點。
如要瞭解如何套用或移除 Terraform 設定,請參閱「基本 Terraform 指令」。
Java
在試用這個範例之前,請先按照「使用用戶端程式庫的 Agent Platform 快速入門導覽課程」中的 Java 設定說明操作。詳情請參閱 Agent Platform Java API 參考文件。
如要向 Agent Platform 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。
Node.js
在試用這個範例之前,請先按照「使用用戶端程式庫的 Agent Platform 快速入門導覽課程」中的 Node.js 設定說明操作。詳情請參閱 Agent Platform Node.js API 參考文件。
如要向 Agent Platform 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證機制」。
Python
如要瞭解如何安裝或更新 Vertex AI SDK for Python,請參閱「安裝 Vertex AI SDK for Python」。 詳情請參閱 Python API 參考文件。