用戶端程式庫方便開發人員呼叫 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, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). 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, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). 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"
試用程式碼範例
如要查看或取得個別程式碼範例,請前往 GitHub 存放區的 java-aiplatform。
用戶端程式庫說明文件
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