將 AI Guard 整合到您的應用程式中,以掃瞄您的 AI 使用情況,檢測有害內容生成、敏感信息洩漏和提示注入。
步驟
- 配置下列AI Guard設定。
- 輸入設定的「名稱」。
- 選取下列選項中的安全層級:
-
謹慎
-
中
-
加強
注意
趨勢科技建議您選取「中」。 -
- 使用切換開關來決定 AI Guard 掃瞄哪些內容類型:
-
Scan for harmful content
-
Scan for sensitive information
-
Scan for prompt attacks
-
- 您可以點擊「Copy settings code」來測試您環境中的AI Guard設定。
- 按一下「套用」以儲存設定。
- 為 AI Guard 建立 API 金鑰。
- 移至「 」。
- 按一下「Add API Key」以建立新 API 金鑰。
- 指定 API 金鑰的名稱、使用者角色和到期時間。
- 按一下「新增」。
- 複製並保留 API 金鑰。
- 將 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") # Configure headers headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } # Prepare the payload for AI security scanning payload = { "guard": "your_prompt_or_response_here" } url = "https://<BASE_V1_URL>/beta/aiSecurity/guard?detailedResponse=false" # Make the API request response = requests.post( url, headers=headers, json=payload ) # Check response status if response.status_code == 200: result = response.json() print("Scan completed successfully") else: print(f"Error: {response.status_code} - {response.text}")
注意
趨勢科技 建議將您的 API 金鑰儲存於 AI Guard 名稱$V1_API_KEY
下。在 API 請求中將以下設置為基礎 URL:<https://api.{region}.xdr.trendmicro.com/beta/aiSecurity>
除非您的 Trend Vision One 帳戶地區是美國(預設地區),否則請在基本 URL 中將{region}
替換為適用的地區代碼:-
eu
-
jp
-
au
-
in
-
sg
-
mea
如需詳細資訊,請參閱AI Guard API 參考。 -