檢視次數:
在您的應用程式中整合 AI Guard,以掃瞄您的 AI 使用情況,檢測有害內容生成、敏感信息洩漏和提示注入。
如需趨勢科技託管的整合,請參閱 整合 Trend 託管的 AI 防護。為了資料主權,請在您的 AWS 環境中部署和託管趨勢科技 Artifact 掃瞄器。Trend Vision One 僅接收掃瞄結果。

步驟

  1. 要設定新的 AWS 帳戶:
    1. Trend Vision One控制台中,前往Cloud SecurityCloud AccountsAWS
    2. 點選Add Account
    3. 對於Deployment Method,選擇CloudFormation
    4. 選取帳號類型:
      • Single AWS Account
      • AWS Organization
    5. 提供「帳號」「說明」以顯示在Cloud Accounts中。
    6. 指定「Organizational Unit ID」。當您新增 AWS 組織時,所有在 AWS 中未指定別名的成員帳戶將在 Cloud Accounts 中收到自動生成的名稱。
  2. 要配置現有的 AWS 帳戶:
    1. 按一下「Update AWS account」,然後按一下帳號名稱。
    2. 「Cloud Accounts Settings」中,點擊「Stack Update」標籤。
  3. 選擇 AWS 區域以部署 CloudFormation 範本。
  4. 要將自訂標籤新增到 Trend Vision One 部署的資源,請選擇Resource tagging並指定鍵值對。
    • 要新增最多三個標籤,請按一下「Create a new tag」
  5. 點選下一步
  6. 啟用「AI Application Security」
  7. 選取「部署」
  8. 選擇「Enable AI Guard」
  9. 在同一瀏覽器會話中的新標籤頁中,使用具有管理員權限的角色登入您要連接的 AWS 帳戶。
  10. 對於現有的 AWS 帳戶
    1. 「Update the CloudFormation template」下,按一下「Copy S3 URL」
    2. 若要在部署前檢視範本,請點擊「Download and Review Template」
    3. 前往「Stacks」,然後點擊您想要更新的堆疊名稱。
      • Vision-One-雲端帳戶管理
    4. 按一下「更新」。
    5. 選擇「Replace current template」
    6. 將範本 S3 URL 貼入「Amazon S3 URL」
    7. 按「下一步」。
  11. 對於新的 AWS 帳戶
    1. 按「下一步」。
    2. 要使用自動部署:
      1. 選取「Automated」做為部署類型。
      2. 點擊「Launch stack」以在 AWS 控制台中啟動 CloudFormation 範本。
      3. 完成「Quick Create Stack」中的步驟。
    3. 要使用手動部署:
      1. 選取「手動」做為部署類型。
      2. 點擊「Download the template and stack parameters as a .zip」
      3. 前往「CloudFormation」下的「Stacks」
      4. 使用 .zip 檔案中的參數建立新堆疊。
  12. Trend Vision One中,點擊「完成」
  13. 在另一個分頁中,登入 AWS 管理控制台並開啟 CloudFormation 堆疊。
  14. 前往「Outputs」標籤頁並複製GuardAPIEndpoint。
  15. 將 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 的值。