在 Model Garden 中测试模型功能

Model Garden 提供了多种选项,可供您快速查看和测试模型功能。对于受支持的模型,您可以试用演示 Playground,也可以启动名为“Model Garden Spaces”的演示应用,并与他人分享,以展示模型的功能。

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

启动 Spaces 后,您将获得一个可正常运行的 Web 应用,与部署模型并构建应用以使用模型端点相比,所需的人工工作量要少得多。Model Garden 会在 Vertex AI 中部署您选择的模型,并在使用已部署模型端点的 Cloud Run 实例上部署示例应用。应用还可以使用现有端点或 MaaS 端点。

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

准备工作

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

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

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

  4. Enable the Vertex AI API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

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

  7. Enable the Vertex AI API.

    Enable the API

  8. 试用 Playground

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

      前往 Gemma 2

    2. 试用面板中:

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

      Gemma 2b-it 的试用面板

    3. 点击提交。输出结果会显示在“提交”按钮下方。

    试用聊天室

    您可以启动包含 Gemini、Gemma、Llama 和 Stable Diffusion 等模型的空间。以下列表显示了支持的示例:

    IAM 权限

    除了使用 Vertex AI 的现有权限之外,您还必须拥有以下权限才能启动 Spaces:

    操作 所需权限 用途
    启用其他 API serviceusage.services.enable 启用以下 API:
    • Cloud Run Admin API (run.googleapis.com)
    • Artifact Registry API (artifactregistry.googleapis.com)
    • Cloud Build API (cloudbuild.googleapis.com)
    • Cloud Logging API (logging.googleapis.com)
    授予服务账号权限 resourcemanager.projects.setIamPolicy Compute Engine 默认服务账号授予以下角色:
    部署特定权限
    • storage.buckets.create
    • run.services.create
    • artifactregistry.repositories.create
    • run.services.setIamPolicy
    在部署期间,一组源代码将上传到 Cloud Storage,然后部署到 Cloud Run,并创建一项新服务。需要提供 artifactregistry.repositories.create 才能为容器映像创建代码库。需要 run.services.setIamPolicy 才能使服务可公开访问。

    如果您是项目的所有者,则无需采取其他操作,只需按照 Vertex AI Studio 中的指南操作即可。如果您不是项目的负责人,请让项目管理员执行前两项操作,然后授予您编辑者 (roles/editor) 和 Cloud Run 管理员 (roles/run.admin) 角色。

    启动聊天室

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

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

      转到 Model Garden

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

      前往 Gemma 3

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

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

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

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

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

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

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

    清理

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

    删除聊天室

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

    删除模型资源

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

    如需手动删除 Vertex AI 资源,请参阅取消部署模型并删除资源

    删除 Cloud Run 服务

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

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

      转到 Cloud Run

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

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

    删除项目

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

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

    1. In the Google Cloud console, go to the Manage resources page.

      Go to Manage resources

    2. In the project list, select the project that you want to delete, and then click Delete.
    3. In the dialog, type the project ID, and then click Shut down to delete the project.

    后续步骤

    查看 Model Garden 概览