Öffentlichen Endpunkt erstellen

Wenn Sie ein Modell mit der gcloud CLI oder der Vertex AI API bereitstellen möchten, müssen Sie zuerst einen öffentlichen Endpunkt erstellen.

Wenn Sie bereits einen öffentlichen Endpunkt haben, können Sie diesen Schritt überspringen und mit Modell mit der gcloud CLI oder der Vertex AI API bereitstellen fortfahren.

In diesem Dokument wird beschrieben, wie Sie einen neuen öffentlichen Endpunkt erstellen.

Das standardmäßige Zeitlimit für Anfragen an einen dedizierten öffentlichen Endpunkt beträgt 10 Minuten. In der Vertex AI API und im Vertex AI SDK für Python können Sie optional eine andere Zeitüberschreitung für Anfragen angeben, indem Sie ein clientConnectionConfig-Objekt mit einem neuen inferenceTimeout-Wert hinzufügen, wie im folgenden Beispiel gezeigt. Der maximale Zeitüberschreitungswert beträgt 3.600 Sekunden (1 Stunde).

Google Cloud Console

  1. Rufen Sie in der Google Cloud Console im Abschnitt Vertex AI die Seite Onlinevorhersage auf.
    Zur Seite „Onlinevorhersage“
  2. Klicken Sie auf Erstellen.
  3. Im Bereich Neuer Endpunkt:
    1. Geben Sie den Endpunktnamen ein.
    2. Wählen Sie als Zugriffstyp Standard aus.
    3. Klicken Sie das Kästchen Dediziertes DNS aktivieren an.
    4. Klicken Sie auf Weiter.
  4. Klicken Sie auf Fertig.

REST

Ersetzen Sie diese Werte in den folgenden Anfragedaten:

  • LOCATION_ID: Ihre Region.
  • PROJECT_ID: Ihre Projekt-ID.
  • ENDPOINT_NAME: Der Anzeigename für den Endpunkt.
  • INFERENCE_TIMEOUT_SECS: (Optional) Anzahl der Sekunden im optionalen Feld inferenceTimeout.

HTTP-Methode und URL:

POST https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/endpoints

JSON-Text anfordern:

{
  "display_name": "ENDPOINT_NAME"
  "dedicatedEndpointEnabled": true,
  "clientConnectionConfig": {
    "inferenceTimeout": {
      "seconds": INFERENCE_TIMEOUT_SECS
    }
  }
}

Wenn Sie die Anfrage senden möchten, maximieren Sie eine der folgenden Optionen:

Sie sollten eine JSON-Antwort ähnlich wie diese erhalten:

{
  "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"
    }
  }
}
Sie können den Status des Vorgangs abfragen, bis in der Antwort "done": true angegeben wird.

Python

Bevor Sie dieses Beispiel anwenden, folgen Sie den Python-Einrichtungsschritten in der Vertex AI-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der Referenzdokumentation zur Vertex AI Python API.

Richten Sie zur Authentifizierung bei Vertex AI Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

Ersetzen Sie Folgendes:

  • PROJECT_ID: Ihre Projekt-ID.
  • LOCATION_ID: Die Region, in der Sie Vertex AI verwenden.
  • ENDPOINT_NAME: Der Anzeigename für den Endpunkt.
  • INFERENCE_TIMEOUT_SECS: (Optional) Anzahl der Sekunden im optionalen Wert 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,
)

Gemeinsam genutzten öffentlichen Endpunkt erstellen

Google Cloud Console

  1. Rufen Sie in der Google Cloud Console im Abschnitt Vertex AI die Seite Onlinevorhersage auf.
    Zur Seite „Onlinevorhersage“
  2. Klicken Sie auf Erstellen.
  3. Im Bereich Neuer Endpunkt:
    1. Geben Sie den Endpunktnamen ein.
    2. Wählen Sie als Zugriffstyp Standard aus.
    3. Klicken Sie auf Weiter.
  4. Klicken Sie auf Fertig.

gcloud

Im folgenden Beispiel wir der Befehl gcloud ai endpoints create verwendet:

gcloud ai endpoints create \
    --region=LOCATION_ID \
    --display-name=ENDPOINT_NAME

Ersetzen Sie dabei Folgendes:

  • LOCATION_ID: Die Region, in der Sie Vertex AI verwenden.
  • ENDPOINT_NAME: Der Anzeigename für den Endpunkt.

Es kann einige Sekunden dauern, bis das Google Cloud CLI den Endpunkt erstellt.

REST

Ersetzen Sie diese Werte in den folgenden Anfragedaten:

  • LOCATION_ID: Ihre Region.
  • PROJECT_ID: Ihre Projekt-ID.
  • ENDPOINT_NAME: Der Anzeigename für den Endpunkt.

HTTP-Methode und URL:

POST https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/endpoints

JSON-Text anfordern:

{
  "display_name": "ENDPOINT_NAME"
}

Wenn Sie die Anfrage senden möchten, maximieren Sie eine der folgenden Optionen:

Sie sollten eine JSON-Antwort ähnlich wie diese erhalten:

{
  "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"
    }
  }
}
Sie können den Status des Vorgangs abfragen, bis in der Antwort "done": true angegeben wird.

Terraform

Im folgenden Beispiel wird die Terraform-Ressource google_vertex_ai_endpoint verwendet, um einen Endpunkt zu erstellen.

Informationen zum Anwenden oder Entfernen einer Terraform-Konfiguration finden Sie unter Grundlegende Terraform-Befehle.

# Endpoint name must be unique for the project
resource "random_id" "endpoint_id" {
  byte_length = 4
}

resource "google_vertex_ai_endpoint" "default" {
  name         = substr(random_id.endpoint_id.dec, 0, 10)
  display_name = "sample-endpoint"
  description  = "A sample Vertex AI endpoint"
  location     = "us-central1"
  labels = {
    label-one = "value-one"
  }
}

Java

Bevor Sie dieses Beispiel anwenden, folgen Sie den Java-Einrichtungsschritten in der Vertex AI-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der Referenzdokumentation zur Vertex AI Java API.

Richten Sie zur Authentifizierung bei Vertex AI Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.


import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.aiplatform.v1.CreateEndpointOperationMetadata;
import com.google.cloud.aiplatform.v1.Endpoint;
import com.google.cloud.aiplatform.v1.EndpointServiceClient;
import com.google.cloud.aiplatform.v1.EndpointServiceSettings;
import com.google.cloud.aiplatform.v1.LocationName;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class CreateEndpointSample {

  public static void main(String[] args)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.
    String project = "YOUR_PROJECT_ID";
    String endpointDisplayName = "YOUR_ENDPOINT_DISPLAY_NAME";
    createEndpointSample(project, endpointDisplayName);
  }

  static void createEndpointSample(String project, String endpointDisplayName)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    EndpointServiceSettings endpointServiceSettings =
        EndpointServiceSettings.newBuilder()
            .setEndpoint("us-central1-aiplatform.googleapis.com:443")
            .build();

    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (EndpointServiceClient endpointServiceClient =
        EndpointServiceClient.create(endpointServiceSettings)) {
      String location = "us-central1";
      LocationName locationName = LocationName.of(project, location);
      Endpoint endpoint = Endpoint.newBuilder().setDisplayName(endpointDisplayName).build();

      OperationFuture<Endpoint, CreateEndpointOperationMetadata> endpointFuture =
          endpointServiceClient.createEndpointAsync(locationName, endpoint);
      System.out.format("Operation name: %s\n", endpointFuture.getInitialFuture().get().getName());
      System.out.println("Waiting for operation to finish...");
      Endpoint endpointResponse = endpointFuture.get(300, TimeUnit.SECONDS);

      System.out.println("Create Endpoint Response");
      System.out.format("Name: %s\n", endpointResponse.getName());
      System.out.format("Display Name: %s\n", endpointResponse.getDisplayName());
      System.out.format("Description: %s\n", endpointResponse.getDescription());
      System.out.format("Labels: %s\n", endpointResponse.getLabelsMap());
      System.out.format("Create Time: %s\n", endpointResponse.getCreateTime());
      System.out.format("Update Time: %s\n", endpointResponse.getUpdateTime());
    }
  }
}

Node.js

Bevor Sie dieses Beispiel anwenden, folgen Sie den Node.js-Einrichtungsschritten in der Vertex AI-Kurzanleitung zur Verwendung von Clientbibliotheken. Weitere Informationen finden Sie in der Referenzdokumentation zur Vertex AI Node.js API.

Richten Sie zur Authentifizierung bei Vertex AI Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

/**
 * TODO(developer): Uncomment these variables before running the sample.\
 * (Not necessary if passing values as arguments)
 */

// const endpointDisplayName = 'YOUR_ENDPOINT_DISPLAY_NAME';
// const project = 'YOUR_PROJECT_ID';
// const location = 'YOUR_PROJECT_LOCATION';

// Imports the Google Cloud Endpoint Service Client library
const {EndpointServiceClient} = require('@google-cloud/aiplatform');

// Specifies the location of the api endpoint
const clientOptions = {
  apiEndpoint: 'us-central1-aiplatform.googleapis.com',
};

// Instantiates a client
const endpointServiceClient = new EndpointServiceClient(clientOptions);

async function createEndpoint() {
  // Configure the parent resource
  const parent = `projects/${project}/locations/${location}`;
  const endpoint = {
    displayName: endpointDisplayName,
  };
  const request = {
    parent,
    endpoint,
  };

  // Get and print out a list of all the endpoints for this resource
  const [response] = await endpointServiceClient.createEndpoint(request);
  console.log(`Long running operation : ${response.name}`);

  // Wait for operation to complete
  await response.promise();
  const result = response.result;

  console.log('Create endpoint response');
  console.log(`\tName : ${result.name}`);
  console.log(`\tDisplay name : ${result.displayName}`);
  console.log(`\tDescription : ${result.description}`);
  console.log(`\tLabels : ${JSON.stringify(result.labels)}`);
  console.log(`\tCreate time : ${JSON.stringify(result.createTime)}`);
  console.log(`\tUpdate time : ${JSON.stringify(result.updateTime)}`);
}
createEndpoint();

Vertex AI SDK für Python

Informationen zur Installation des Vertex AI SDK for Python finden Sie unter Vertex AI SDK for Python installieren. Weitere Informationen finden Sie in der Referenzdokumentation zur Vertex AI SDK for Python API.

def create_endpoint_sample(
    project: str,
    display_name: str,
    location: str,
):
    aiplatform.init(project=project, location=location)

    endpoint = aiplatform.Endpoint.create(
        display_name=display_name,
        project=project,
        location=location,
    )

    print(endpoint.display_name)
    print(endpoint.resource_name)
    return endpoint

Nächste Schritte