Model Armor 与 Google Cloud 服务的集成

Model Armor 可与各种 Google Cloud 服务集成:

  • Google Kubernetes Engine (GKE) 和 Service Extensions
  • Vertex AI
  • Google Agentspace

GKE 和 Service Extensions

Model Armor 可通过 Service Extensions 与 GKE 集成。借助 Service Extensions,您可以集成内部(Google Cloud 服务)或外部(用户管理的)服务来处理流量。您可以在应用负载均衡器(包括 GKE 推理网关)上配置服务扩展程序,以筛查进出 GKE 集群的流量。这可验证与 AI 模型的所有互动都受 Model Armor 保护。如需了解详情,请参阅与 GKE 集成

Vertex AI

Model Armor 可以使用下限设置模板直接集成到 Vertex AI 中。此集成会过滤 Gemini 模型请求和回答,并阻止违反下限设置的请求和回答。此集成功能可为 generateContent 方法提供 Vertex AI 中的 Gemini API 中的提示和回答保护。您需要启用 Cloud Logging,才能查看提示和回答的清理结果。如需了解详情,请参阅与 Vertex AI 集成

Google Agentspace

Model Armor 可通过模板直接与 Google Agentspace 集成。Google Agentspace 通过 Model Armor 路由用户与智能体之间的互动以及与底层 LLM 的互动。这意味着,Model Armor 会先检查用户或智能体的提示以及 LLM 生成的回答,然后才会将它们呈现给用户。如需了解详情,请参阅与 Google Agentspace 集成

准备工作

启用 API

您必须先启用 Model Armor API,然后才能使用 Model Armor。

控制台

  1. Enable the Model Armor API.

    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 API

  2. 选择要启用 Model Armor 的项目。

gcloud

在开始之前,请使用 Google Cloud CLI 和 Model Armor API 按照以下步骤操作:

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. 运行以下命令,为 Model Armor 服务设置 API 端点。

    gcloud config set api_endpoint_overrides/modelarmor "https://modelarmor.LOCATION.rep.googleapis.com/"

    LOCATION 替换为您要使用 Model Armor 的区域。

  3. 运行以下命令以启用 Model Armor。

      gcloud services enable modelarmor.googleapis.com --project=PROJECT_ID
       

    PROJECT_ID 替换为相应项目的 ID。

    集成 Model Armor 时的选项

    Model Armor 提供以下集成选项。每种方案都提供不同的特性和功能。

    集成选项 政策实施程序/检测器 配置检测 仅检查 检查并屏蔽 模型和云覆盖范围
    REST API 检测器 仅使用模板 所有模型和所有云
    Vertex AI预览版 内嵌强制执行 使用下限设置模板 Google Cloud上的 Gemini(非流式传输)
    Google Kubernetes Engine 内嵌强制执行 仅使用模板 Google Cloud上采用 OpenAI 格式的模型
    Google Agentspace 内嵌强制执行 仅使用模板 所有模型和所有云

    对于 REST API 集成选项,Model Armor 只是作为一个使用模板的检测器来运行。这意味着,它只会根据预定义的模板识别和报告潜在的违规行为,而不会主动阻止这些行为。在与 Model Armor API 集成后,您的应用可以使用其输出,根据提供的安全评估结果来阻止或允许操作。Model Armor API 会返回与您的 API 流量相关的潜在威胁或违规行为信息,尤其是在与 AI/LLM 互动的情况下。您的应用可以调用 Model Armor API,并使用响应中收到的信息来根据预定义的自定义逻辑做出决策并采取相应措施。

    借助 Vertex AI 集成选项,Model Armor 可使用下限设置或模板提供内嵌强制执行。这意味着,Model Armor 会直接介入流程来主动执行政策,而无需修改应用代码。

    与 Vertex AI 类似,GKE 集成和 Google Agentspace 集成选项也只会通过模板实现内嵌强制执行。这意味着,Model Armor 可以在推理网关内直接强制执行政策,或是在 Google Agentspace 实例内的用户或智能体互动中直接强制执行政策,而无需修改应用代码。

    Model Armor 与 Google Agentspace 的集成只会清理初始的用户提示和最终的智能体或模型回答。初始的用户提示与最终生成的回答之间发生的任何中间步骤都不在此集成涵盖范围内。