用戶端程式庫會提供經過最佳化處理的開發人員服務,方便您呼叫 Agent Platform API。用戶端程式庫採用每種支援語言的自然慣例,並減少您必須編寫的樣板程式碼。下列指南說明如何安裝程式庫,以及設定驗證,以便在本機開發環境中使用這些程式庫。
事前準備
- 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自評估產品在實際工作環境中的成效。新客戶還能獲得價值 $300 美元的免費抵免額,可用於執行、測試及部署工作負載。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Agent Platform API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Agent Platform API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
如果您使用本機殼層,請為使用者帳戶建立本機驗證憑證:
gcloud auth application-default login
如果您使用 Cloud Shell,則不需要執行這項操作。
如果系統傳回驗證錯誤,且您使用外部識別資訊提供者 (IdP),請確認您已 使用聯合身分登入 gcloud CLI。
用戶端程式庫
Agent Platform 提供下列語言的用戶端程式庫:選取要使用的語言。
C#
執行下列指令,將 Google.Cloud.AIPlatform.V1 套件參照新增至專案檔案:
dotnet add package Google.Cloud.AIPlatform.V1
試用程式碼範例
如要查看或取得個別程式碼範例,請前往 dotnet-aiplatform GitHub 存放區。
用戶端程式庫說明文件
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 存放區。
用戶端程式庫說明文件
Node.js
安裝程式庫前,請先設定適當的 Node.js 開發環境。
在環境中執行下列指令,安裝用戶端程式庫:
npm install @google-cloud/aiplatform
用戶端程式庫說明文件
Python
安裝 Agent Platform SDK for Python 時,系統會一併安裝 Gemini Enterprise Agent Platform Python 用戶端程式庫。
詳情請參閱「安裝 Agent Platform SDK for Python」。
Go
安裝程式庫前,請設定適當的 Go 開發環境。
查看可用的套件
查看可用的 Agent Platform API Go 封裝,判斷最符合專案需求的封裝:
套件 cloud.google.com/go/vertexai (建議使用)
vertexai是由人為撰寫的套件,可提供常見功能和特性的存取權。建議大多數開發人員從這個套件著手,使用 Agent Platform API 建構應用程式。如要存取這個套件尚未涵蓋的功能,請改用自動產生的
aiplatform。套件 cloud.google.com/go/aiplatform
「
aiplatform」是自動產生的套件。這個套件適用於需要存取 Agent Platform API 功能的專案,這些功能目前尚未由人工撰寫的
vertexai套件提供。
安裝
套件 cloud.google.com/go/vertexai (建議使用)
執行下列指令,在環境中安裝這個套件:
go get cloud.google.com/go/vertexai套件 cloud.google.com/go/aiplatform
執行下列指令,在環境中安裝這個套件:
go get cloud.google.com/go/aiplatform
範例
套件 cloud.google.com/go/vertexai (建議使用)
如需使用這個套件的範例,請前往頂層
vertexai目錄的golang-samplesGitHub 存放區:套件 cloud.google.com/go/aiplatform
如需使用這個套件的範例,請前往頂層
aiplatform目錄的golang-samplesGitHub 存放區:
用戶端程式庫說明文件
如要進一步瞭解程式庫,請參閱 Go 語言適用的 Agent Platform 用戶端程式庫說明文件:
套件 cloud.google.com/go/vertexai (建議使用)
- Gemini Enterprise Agent Platform
cloud.google.com/go/vertexaiAPI 參考資料
- Gemini Enterprise Agent Platform