用戶端程式庫方便開發人員呼叫 Agent Platform API,提供最優質的體驗。用戶端程式庫會使用各支援語言的自然慣例,並減少您必須編寫的樣板程式碼。下列指南說明如何安裝程式庫,並設定驗證機制,以便在本機開發環境中使用。
事前準備
-
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
如果傳回驗證錯誤,請確認您已使用聯合身分登入 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 (建議)
如需使用這個套件的範例,請前往
golang-samplesGitHub 存放區的頂層vertexai目錄:套件 cloud.google.com/go/aiplatform
如需使用這個套件的範例,請前往
golang-samplesGitHub 存放區的頂層aiplatform目錄:
用戶端程式庫說明文件
如要進一步瞭解程式庫,請參閱 Go 專用 Agent Platform 用戶端程式庫說明文件:
套件 cloud.google.com/go/vertexai (建議)
- Gemini Enterprise Agent Platform
cloud.google.com/go/vertexaiAPI 參考資料
- Gemini Enterprise Agent Platform