客户端库提供了优化 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.-
如果您使用的是本地 shell,请为您的用户账号创建本地身份验证凭证:
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 代码库。
客户端库文档
如需了解详情,请参阅 Agent Platform .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 版 Agent Platform 客户端库文档。
Node.js
在安装库之前,请准备好您的 Node.js 开发环境。
在您的环境中运行以下命令来安装客户端库:
npm install @google-cloud/aiplatform
客户端库文档
如需了解详情,请参阅 Node.js 版 Agent Platform 客户端库文档。
Python
Gemini Enterprise Agent Platform Python 客户端库会在您安装 Agent Platform SDK for 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是自动生成的软件包。此软件包适用于需要访问人工编写的
vertexai软件包尚未提供的 Agent Platform API 功能和特性的项目。
安装
软件包 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