在 Model Garden 中测试模型功能

Model Garden 提供了多种选项,可供您快速查看和测试模型功能。对于支持的模型,您可以试用演示园地或启动名为 Model Garden 空间的演示应用,可将这些内容与他人共享以展示模型的功能。

园地由预部署的 Gemini Enterprise Agent Platform 在线预测端点提供支持,不会产生费用。打开支持的模型对应的模型卡片后,您可以使用试用面板,通过发送文本提示来快速测试模型的功能。您还可以设置一些最常见的参数,例如温度和输出 token 数量。园地仅限文本输入和输出。

启动空间后,您将获得一个可正常运行的 Web 应用,该应用已准备就绪可供使用,与部署模型并构建应用以使用模型端点相比,所需的手动工作量要少得多。Model Garden 会在 Gemini Enterprise Agent Platform 中部署您选择的模型,并在一个 Cloud Run 实例上部署使用所部署模型端点的示例应用。该应用还可以使用现有端点或 MaaS 端点。

准备工作

本教程需要您设置 Google Cloud 项目并启用 Agent Platform API。

  1. 登录您的 Google Cloud 账号。如果您是 Google Cloud新手,请 创建一个账号来评估我们的产品在实际场景中的表现。新客户还可获享 $300 赠金,用于运行、测试和部署工作负载。
  2. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  4. Verify that billing is enabled for your Google Cloud project.

  5. Enable the Gemini Enterprise Agent Platform, Artifact Registry, Cloud Build, Cloud Logging, and Cloud Run Admin APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  6. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  7. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  8. Verify that billing is enabled for your Google Cloud project.

  9. Enable the Gemini Enterprise Agent Platform, Artifact Registry, Cloud Build, Cloud Logging, and Cloud Run Admin APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  10. 如果您想试用 Model Garden Spaces,请验证 Compute Engine 默认服务账号是否具有启动 Spaces 所需的权限

所需的角色

如需在 Model Garden 中测试模型功能,请确保您和 Compute Engine 默认服务账号都具有所需的 IAM 角色。

用户所需的角色

如需获得在 Model Garden 中测试模型功能所需的权限,请让您的管理员为您授予 Google Cloud 项目的以下 IAM 角色:

如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限

您也可以通过自定义角色或其他预定义角色来获取所需的权限。

Compute Engine 默认服务账号所需的角色

Compute Engine 默认服务账号用于启动空间。

为确保 Compute Engine 默认服务账号具有启动 Spaces 所需的权限,请让您的管理员为 Google Cloud 项目中的 Compute Engine 默认服务账号授予以下 IAM 角色:

如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限

您的管理员也可以通过自定义角色或其他预定义角色为 Compute Engine 默认服务账号授予所需的权限。

试用园地

  1. 在 Google Cloud 控制台中,前往支持的模型的模型卡片,例如 Gemma 2 模型卡片。

    前往 Gemma 2

  2. 试用面板中:

    1. 对于区域,接受默认值或选择您的区域。
    2. 对于端点,选择演示园地
    3. 提示框中,输入 Why is the sky blue?
    4. 展开高级选项部分,然后查看默认参数。

    Gemma 2b-it 的试用面板

  3. 点击提交。输出会出现在“提交”按钮下方。

试用空间

如需启动模型,请打开支持的模型对应的模型卡片,然后在试用空间面板中,点击某个空间以启动它。您需要为部署所用的机器以及托管应用的 Cloud Run 实例付费。

您可以启动包含 Gemini、Gemma、Llama 和 Stable Diffusion 等模型的空间。

启动空间

启动空间,以测试和尝试来自示例 Gradio 应用的模型。

  1. 在 Google Cloud 控制台中,前往 Model Garden 以查看模型的模型卡片。

    转到 Model Garden

  2. 选择要使用的模型。支持的模型具有试用空间面板,例如 Gemma 3 模型卡片。

    前往 Gemma 3

  3. 点击 rocket_launch 运行以启动空间。

    1. 您可以选择需要进行身份验证(通过 Identity-Aware Proxy)或允许公开访问。如需了解详情,请参阅为首次部署启用 API 并授予权限
    1. 点击创建新服务以开始部署。您可以在模型卡片中监控部署状态。
  4. 当空间状态变为准备就绪后,点击它即可查看有关部署的详细信息。

    为了提供基本保护,Web 应用需要一个密钥,该密钥在提交提示时必须附加到网址中。此密钥在密钥字段中提供。

    1. 点击打开可开始使用应用。您可以在应用内向模型发送提示并查看其回答。

    您可以共享网址,以便其他人也可以试用应用。

    1. 如需关闭对应用的访问权限,请点击访问权限控制字段中的 修改

    在 Cloud Run 应用的安全标签页中,选择需要进行身份验证,然后点击保存。应用便再也无法通过相应网址访问。访问相应网址会导致 403 错误(禁止访问)。

清理

为避免因本页中使用的资源导致您的 Google Cloud 账号产生费用,请按照以下步骤操作。

删除空间

如需清理空间,您必须删除模型资源和 Cloud Run 上的示例应用资源。

删除模型资源

在 Gradio 应用中,您可以删除模型端点以清理 Gemini Enterprise Agent Platform 资源。然后,您需要删除 Cloud Run 服务,以停止并删除 Gradio 应用。

如需手动删除 Gemini Enterprise Agent Platform 资源,请参阅取消部署模型并删除资源

删除 Cloud Run 服务

删除与服务相关的资源,包括服务的所有修订版本。删除服务不会删除 Artifact Registry 中的容器映像等项目。如需了解详情,请参阅 Cloud Run 文档中的管理服务

  1. 在 Google Cloud 控制台中,查看 Cloud Run 服务列表:

    转到 Cloud Run

  2. 找到要删除的服务,然后选择该服务。

  3. 点击 delete 删除。这将删除服务的所有修订版本。

删除项目

为了避免产生费用,最简单的方法是删除您为本教程创建的项目。

要删除项目,请执行以下操作:

  1. 在 Google Cloud 控制台中,前往管理资源页面。

    转到“管理资源”

  2. 在项目列表中,选择要删除的项目,然后点击删除
  3. 在对话框中输入项目 ID,然后点击关闭以删除项目。

后续步骤

查看 Model Garden 概览