在您的應用程式中整合 AI Guard,以掃瞄您的 AI 使用情況,檢測有害內容生成、敏感信息洩漏和提示注入。
如需趨勢科技託管的整合,請參閱 整合 Trend 託管的 AI 防護。為了資料主權,請在您的 AWS 環境中部署和託管趨勢科技 Artifact 掃瞄器。Trend Vision One 僅接收掃瞄結果。
步驟
- 要設定新的 AWS 帳戶:
- 在Trend Vision One控制台中,前往。
- 點選Add Account。
- 對於Deployment Method,選擇CloudFormation。
- 選取帳號類型:
-
Single AWS Account
-
AWS Organization
-
- 提供「帳號」和「說明」以顯示在Cloud Accounts中。
- 指定「Organizational Unit ID」。當您新增 AWS 組織時,所有在 AWS 中未指定別名的成員帳戶將在 Cloud Accounts 中收到自動生成的名稱。
- 要配置現有的 AWS 帳戶:
- 按一下「Update AWS account」,然後按一下帳號名稱。
- 在「Cloud Accounts Settings」中,點擊「Stack Update」標籤。
- 選擇 AWS 區域以部署 CloudFormation 範本。
- 要將自訂標籤新增到 Trend Vision One 部署的資源,請選擇Resource tagging並指定鍵值對。
-
要新增最多三個標籤,請按一下「Create a new tag」。
-
- 點選下一步。
- 啟用「AI Application Security」。
- 選取「部署」。
- 選擇「Enable AI Guard」。
- 在同一瀏覽器會話中的新標籤頁中,使用具有管理員權限的角色登入您要連接的 AWS 帳戶。
- 對於現有的 AWS 帳戶:
- 在「Update the CloudFormation template」下,按一下「Copy S3 URL」。
- 若要在部署前檢視範本,請點擊「Download and Review Template」。
- 前往「Stacks」,然後點擊您想要更新的堆疊名稱。
-
Vision-One-雲端帳戶管理
-
- 按一下「更新」。
- 選擇「Replace current template」。
- 將範本 S3 URL 貼入「Amazon S3 URL」。
- 按「下一步」。
- 對於新的 AWS 帳戶:
- 按「下一步」。
- 要使用自動部署:
-
選取「Automated」做為部署類型。
-
點擊「Launch stack」以在 AWS 控制台中啟動 CloudFormation 範本。
-
完成「Quick Create Stack」中的步驟。
-
- 要使用手動部署:
-
選取「手動」做為部署類型。
-
點擊「Download the template and stack parameters as a .zip」。
-
前往「CloudFormation」下的「Stacks」。
-
使用 .zip 檔案中的參數建立新堆疊。
-
- 在Trend Vision One中,點擊「完成」。
- 在另一個分頁中,登入 AWS 管理控制台並開啟 CloudFormation 堆疊。
- 前往「Outputs」標籤頁並複製GuardAPIEndpoint。
- 將 AI Guard 整合到您的應用程式中。請參考以下程式碼片段進行整合。
import os import requests # Get your Trend Vision One API key from environment variable api_key = os.environ.get("V1_API_KEY") if not api_key: raise ValueError("Missing V1_API_KEY environment variable") # Get your Trend Micro AI Guard URL from environment variable ai_guard_url = os.environ.get("AI_GUARD_URL") if not ai_guard_url: raise ValueError("Missing AI_GUARD_URL environment variable") # Configure headers headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json", "TMV1-Application-Name": "your-application-name" # Required } # Prepare the payload payload = { "prompt": "Your prompt or message here" } # Copy AI Guard URL from AWS template Stack Output url = f"{ai_guard_url}" # Make the API request response = requests.post( url, headers=headers, json=payload ) # Check response status if response.status_code == 200: result = response.json() # API returns action and optional reasons action = result.get("action") reasons = result.get("reasons", []) if action == "Allow": print("Request allowed by AI Guard") elif action == "Block": print(f"Request blocked by AI Guard") print(f"Reasons: {', '.join(reasons)}") print(f"Response ID: {result.get('id')}") else: print(f"Error: {response.status_code} - {response.text}")-
使用 GuardAPIEndpoint 的值來設定 AI_GUARD_URL 的值。
如需詳細資訊,請參閱AI Guard API 參考和程式碼範例及趨勢科技自動化中心。 -
