Model Armor 與 Google Cloud 服務的整合

Model Armor 可與各種 Google Cloud 服務整合:

  • Google Kubernetes Engine (GKE) 和服務擴充功能
  • Vertex AI
  • Gemini Enterprise

GKE 和 Service Extensions

您可以透過 Service Extensions 將 Model Armor 與 GKE 整合。Service Extensions 可讓您整合內部 (Google Cloud 服務) 或外部 (使用者管理) 服務,以處理流量。您可以在應用程式負載平衡器 (包括 GKE 推論閘道) 上設定服務擴充功能,篩選進出 GKE 叢集的流量。這項功能可確保所有與 AI 模型的互動都受到 Model Armor 保護。詳情請參閱「與 GKE 整合」。

Vertex AI

您可以透過底限設定範本,將 Model Armor 直接整合至 Vertex AI。這項整合功能會篩選 Gemini 模型要求和回覆,並封鎖違反底限設定的內容。這項整合功能會在 Vertex AI 的 Gemini API 中,為 generateContent 方法提供提示和回覆保護機制。您必須啟用 Cloud Logging,才能查看提示和回覆的清除結果。詳情請參閱「與 Vertex AI 整合」。

Gemini Enterprise

您可以使用範本,直接將 Model Armor 整合至 Gemini Enterprise。Gemini Enterprise 會透過 Model Armor,將使用者與代理程式和基礎 LLM 之間的互動路徑導向。也就是說,系統會先透過 Model Armor 檢查使用者或服務專員的提示,以及 LLM 生成的回覆,再呈現給使用者。詳情請參閱「與 Gemini Enterprise 整合」。

事前準備

啟用 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 內嵌強制執行 只使用範本 OpenAI 格式的模型 Google Cloud
    Gemini Enterprise 內嵌強制執行 僅使用範本 所有模型和所有雲端

    如果是 REST API 整合選項,Model Armor 只能使用範本做為偵測器。也就是說,這項功能會根據預先定義的範本,找出並回報潛在的政策違規行為,而不是主動防範。整合 Model Armor API 後,應用程式就能根據提供的安全性評估結果,使用輸出內容封鎖或允許動作。Model Armor API 會傳回與 API 流量相關的潛在威脅或違規情形資訊,特別是 AI/LLM 互動。應用程式可以呼叫 Model Armor API,並根據回應中收到的資訊,按照預先定義的自訂邏輯做出決策及採取行動。

    透過 Vertex AI 整合選項,Model Armor 可使用底價設定或範本提供內嵌強制執行功能。也就是說,Model Armor 會直接介入程序,主動強制執行政策,不需修改應用程式程式碼。

    GKE 和 Gemini Enterprise 整合功能只會使用範本,強制執行內嵌政策。也就是說,Model Armor 可以直接強制執行政策,您不需要在 GKE 推論閘道內,以及在 Gemini Enterprise 執行個體內的使用者或代理程式互動期間,修改應用程式程式碼。

    整合 Model Armor 和 Gemini Enterprise 後,系統只會清理初始使用者提示,以及最終的代理程式或模型回覆。從使用者最初的提示到最終生成的回覆之間,任何中間步驟都不會納入這項整合功能。

    Security Command Center 中的 Model Armor

    Model Armor 會檢查 LLM 提示詞和回覆,找出各種威脅,包括提示詞注入、越獄活動、惡意網址和有害內容。當 Model Armor 偵測到違反已設定底限的情況時,會封鎖提示或回覆,並將發現項目傳送至 Security Command Center。詳情請參閱「Model Armor 發現」。