Membuat daftar model yang disesuaikan untuk Vertex LLM (AI Generatif)

Contoh kode yang menunjukkan cara mendapatkan daftar model yang disesuaikan untuk LLM Vertex

Contoh kode

Java

Sebelum mencoba contoh ini, ikuti petunjuk penyiapan Java di Panduan memulai Vertex AI menggunakan library klien. Untuk mengetahui informasi selengkapnya, lihat Dokumentasi referensi API Java Vertex AI.

Untuk melakukan autentikasi ke Vertex AI, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


import com.google.cloud.aiplatform.v1.ListModelsRequest;
import com.google.cloud.aiplatform.v1.LocationName;
import com.google.cloud.aiplatform.v1.Model;
import com.google.cloud.aiplatform.v1.ModelServiceClient;
import com.google.cloud.aiplatform.v1.ModelServiceClient.ListModelsPagedResponse;
import com.google.cloud.aiplatform.v1.ModelServiceSettings;
import java.io.IOException;

public class ListTunedModelsSample {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace this variable before running the sample.
    String project = "YOUR_PROJECT_ID";

    String location = "us-central1";
    String model = "text-bison@001";

    listTunedModelsSample(project, location, model);
  }

  // List tuned models for a large language model
  public static void listTunedModelsSample(String project, String location, String model)
      throws IOException {
    final String endpoint = String.format("%s-aiplatform.googleapis.com:443", location);
    ModelServiceSettings modelServiceSettings =
        ModelServiceSettings.newBuilder().setEndpoint(endpoint).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.
    try (ModelServiceClient modelServiceClient = ModelServiceClient.create(modelServiceSettings)) {
      final String parent = LocationName.of(project, location).toString();
      final String filter =
          String.format("labels.google-vertex-llm-tuning-base-model-id=%s", model);
      ListModelsRequest request =
          ListModelsRequest.newBuilder().setParent(parent).setFilter(filter).build();

      ListModelsPagedResponse listModelsPagedResponse = modelServiceClient.listModels(request);
      System.out.println("List Tuned Models response");
      for (Model element : listModelsPagedResponse.iterateAll()) {
        System.out.format("\tModel Name: %s\n", element.getName());
        System.out.format("\tModel Display Name: %s\n", element.getDisplayName());
      }
    }
  }
}

Langkah selanjutnya

Untuk menelusuri dan memfilter contoh kode untuk produk Google Cloud lainnya, lihat Google Cloud browser contoh.