יצירת נקודת קצה ציבורית

כדי לפרוס מודל באמצעות ה-CLI של gcloud או Gemini Enterprise API, צריך קודם ליצור נקודת קצה ציבורית.

אם כבר יש לכם נקודת קצה ציבורית, אתם יכולים לדלג על השלב הזה ולהמשיך אל פריסת מודל באמצעות ה-CLI של gcloud או Gemini Enterprise API.

במאמר הזה מוסבר איך ליצור נקודת קצה ציבורית חדשה.

ברירת המחדל של הזמן הקצוב לתפוגה של בקשה לנקודת קצה ציבורית ייעודית היא 10 דקות. ב-Gemini Enterprise API וב-Agent Platform SDK ל-Python, אפשר לציין משך זמן קצוב שונה לתפוגת בקשה. כדי לעשות זאת, מוסיפים אובייקט clientConnectionConfig שמכיל ערך חדש של inferenceTimeout, כמו בדוגמה הבאה. ערך הזמן הקצוב לתפוגה המקסימלי הוא 3,600 שניות (שעה אחת).

מסוףGoogle Cloud

  1. במסוף Google Cloud , בקטע Agent Platform, עוברים לדף Online prediction.
    כניסה לדף 'חיזוי אונליין'
  2. לוחצים על יצירה.
  3. בחלונית New endpoint:
    1. מזינים את שם נקודת הקצה.
    2. בוחרים באפשרות רגילה בתור סוג הגישה.
    3. מסמנים את התיבה הפעלת DNS ייעודי.
    4. לוחצים על Continue.
  4. לוחצים על סיום.

REST

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • LOCATION_ID: האזור שלכם.
  • PROJECT_ID: [מזהה הפרויקט](/resource-manager/docs/creating-managing-projects#identifiers). .
  • ENDPOINT_NAME: השם המוצג של נקודת הקצה.
  • INFERENCE_TIMEOUT_SECS: (אופציונלי) מספר השניות בשדה האופציונלי inferenceTimeout.

ה-method של ה-HTTP וכתובת ה-URL:

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

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי Pythonההוראות להגדרה במאמר מדריך למתחילים של Agent Platform באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Agent Platform Python API.

כדי לבצע אימות ב-Agent Platform, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

מחליפים את מה שכתוב בשדות הבאים:

  • PROJECT_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, מטענים (payloads) שגודלם עולה על 10MB לא ייכללו ביומנים.

כדי להפעיל ולהגדיר רישום ביומן של בקשות ותגובות במהלך יצירת נקודת קצה, משתמשים בפרמטרים הבאים, כפי שמוצג בקטע הקוד הבא:

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

  1. במסוף Google Cloud , בקטע Agent Platform, עוברים לדף Online prediction.
    כניסה לדף 'חיזוי אונליין'
  2. לוחצים על יצירה.
  3. בחלונית New endpoint:
    1. מזינים את שם נקודת הקצה.
    2. בוחרים באפשרות רגילה בתור סוג הגישה.
    3. לוחצים על Continue.
  4. לוחצים על סיום.

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: [מזהה הפרויקט](/resource-manager/docs/creating-managing-projects#identifiers). .
  • ENDPOINT_NAME: השם המוצג של נקודת הקצה.

ה-method של ה-HTTP וכתובת ה-URL:

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.

# 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

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי Javaההוראות להגדרה במאמר מדריך למתחילים של Agent Platform באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Agent Platform Java API.

כדי לבצע אימות ב-Agent Platform, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.


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

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי Node.jsההוראות להגדרה במאמר מדריך למתחילים של Agent Platform באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Agent Platform Node.js API.

כדי לבצע אימות ב-Agent Platform, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

/**
 * 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();

Python

במאמר התקנת Vertex AI SDK ל-Python מוסבר איך להתקין או לעדכן את Vertex AI SDK ל-Python. מידע נוסף מופיע ב מאמרי העזרה של 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

המאמרים הבאים