Vertex LLM(生成 AI)用のチューニング済みモデルを一覧表示する

Vertex LLM 用にチューニングされたモデルのリストを取得する方法を示すコードサンプル

もっと見る

このコードサンプルを含む詳細なドキュメントについては、以下をご覧ください。

コードサンプル

Java

このサンプルを試す前に、Vertex AI クイックスタート: クライアント ライブラリの使用にある Java の設定手順を完了してください。詳細については、Vertex AI Java API のリファレンス ドキュメントをご覧ください。

Vertex AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。


import com.google.cloud.aiplatform.v1beta1.ListModelsRequest;
import com.google.cloud.aiplatform.v1beta1.LocationName;
import com.google.cloud.aiplatform.v1beta1.Model;
import com.google.cloud.aiplatform.v1beta1.ModelServiceClient;
import com.google.cloud.aiplatform.v1beta1.ModelServiceClient.ListModelsPagedResponse;
import com.google.cloud.aiplatform.v1beta1.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());
      }
    }
  }
}

Python

このサンプルを試す前に、Vertex AI クイックスタート: クライアント ライブラリの使用にある Python の設定手順を完了してください。詳細については、Vertex AI Python API のリファレンス ドキュメントをご覧ください。

Vertex AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。


import vertexai
from vertexai.language_models import TextGenerationModel

def list_tuned_models(
    project_id: str,
    location: str,
) -> None:
    """List tuned models."""

    vertexai.init(project=project_id, location=location)
    model = TextGenerationModel.from_pretrained("text-bison@002")
    tuned_model_names = model.list_tuned_model_names()
    print(tuned_model_names)

    return tuned_model_names

次のステップ

他の Google Cloud プロダクトに関連するコードサンプルの検索およびフィルタ検索を行うには、Google Cloud のサンプルをご覧ください。