安裝 Vertex AI 用戶端程式庫

用戶端程式庫會提供經過最佳化處理的開發人員服務,方便您呼叫 Vertex AI API。用戶端程式庫採用每種支援語言的自然慣例,並減少您必須編寫的樣板程式碼。下列指南說明如何安裝程式庫,以及設定驗證,以便在本機開發環境中使用這些程式庫。

事前準備

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Enable the Vertex AI API.

    Enable the API

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  5. Enable the Vertex AI API.

    Enable the API

  6. If you're using a local shell, then create local authentication credentials for your user account:

    gcloud auth application-default login

    You don't need to do this if you're using Cloud Shell.

    If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

  7. 用戶端程式庫

    Vertex AI 提供下列語言的用戶端程式庫。 選取要使用的語言。

    C#

    執行下列指令,將 Google.Cloud.AIPlatform.V1 套件參照新增至專案檔案:

    dotnet add package Google.Cloud.AIPlatform.V1
    

    試用程式碼範例

    如要查看或取得個別程式碼範例,請前往 dotnet-aiplatform GitHub 存放區。

    用戶端程式庫說明文件

    詳情請參閱 Vertex AI .NET 用戶端程式庫說明文件

    Java

    如果您使用 Maven,請將下列指令新增至依附元件:

    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-aiplatform</artifactId>
      <version>3.35.0</version>
    </dependency>
    

    如果您使用 Gradle,請將下列指令新增到依附元件中:

    compile 'com.google.cloud:google-cloud-aiplatform:3.35.0'
    

    如果您使用 sbt,請在依附元件中加入以下指令:

    libraryDependencies += "com.google.cloud" % "google-cloud-aiplatform" % "3.35.0"
    

    試用程式碼範例

    如要查看或取得個別程式碼範例,請前往 java-aiplatform GitHub 存放區。

    用戶端程式庫說明文件

    詳情請參閱 Java 適用的 Vertex AI 用戶端程式庫說明文件

    Node.js

    安裝程式庫前,請先設定適當的 Node.js 開發環境

    在環境中執行下列指令,安裝用戶端程式庫:

    npm install @google-cloud/aiplatform
    

    用戶端程式庫說明文件

    詳情請參閱 Node.js 適用的 Vertex AI 用戶端程式庫說明文件

    Python

    安裝 Vertex AI SDK for Python 時,系統會一併安裝 Vertex AI Python 用戶端程式庫。

    詳情請參閱「安裝 Python 適用的 Vertex AI SDK」。

    Go

    安裝程式庫前,請設定適當的 Go 開發環境

    查看可用的套件

    查看可用的 Vertex AI API Go 封裝,判斷最符合專案需求的封裝:

    • 套件 cloud.google.com/go/vertexai (建議使用)

      vertexai 是由人為撰寫的套件,可提供常見功能和特性的存取權。

      建議大多數開發人員從這個套件著手,使用 Vertex AI API 建構服務。如要存取這個套件尚未涵蓋的功能,請改用自動產生的 aiplatform

    • 套件 cloud.google.com/go/aiplatform

      aiplatform」是系統自動產生的套件。

      如果專案需要存取 Vertex AI API 功能,但這些功能尚未由人工撰寫的 vertexai 套件提供,則可使用這個套件。

    安裝

    範例

    用戶端程式庫說明文件

    如要進一步瞭解這個程式庫,請參閱 Go 適用的 Vertex AI 用戶端程式庫說明文件: