檢視次數:

標題

名稱
必要
描述
Authorization
用於驗證的持有者令牌。

查詢參數

名稱
必要
描述
detailedResponse
No
API 回應的詳細程度。
可能的值包括:
  • false:根據AI Guard設定(預設)對您的提示進行簡短評估。
  • true:根據AI Guard設定對您提示進行詳細評估。

要求

OpenAI 聊天完成請求格式:
{
  "model": "us.meta.llama3-1-70b-instruct-v1:0",
  "messages": [
    {
      "role": "user",
      "content": "Your prompt text here"
    }
  ]
}
OpenAI 聊天完成回應格式:
{
  "id": "chatcmpl-8f88f71a-7d42-c548-d587-8fc8a17091b6",
  "object": "chat.completion",
  "created": 1748535080,
  "model": "us.meta.llama3-1-70b-instruct-v1:0",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Response content here",
        "refusal": null
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 139,
    "completion_tokens": 97,
    "total_tokens": 236
  }
}
簡單字串格式:
{
  "guard": "Your prompt text here"
}

回應

範例回應(當 detailedResponse: false 時):
{
    "id": "1234567890abcdef",
    "action": "Block",
    "reason": "[Violation] Policy Name: harmful_content"
  }
範例回應(當 detailedResponse: true 時):
{
    "id": "1234567890abcdef",
    "action": "Allow",
    "reason": "No policy violations detected",
    "harmful_content": [
      {
        "name": "harmful_content",
        "content_violation": false,
        "confidence_score": 0.05
      }
    ],
    "sensitive_information": {
      "content_violation": false,
      "rule": ""
    },
    "prompt_attack": [
      {
        "name": "prompt_injection",
        "content_violation": false,
        "confidence_score": 0.02
      }
    ]
  }
參數
描述
id
AI Guard 評估的唯一識別碼。
action
建議的操作。
可能的值包括:
  • Allow
  • Block
reason
該操作的說明,包括設定違規的詳細資訊。
harmful_content
在輸入或輸出中檢測到任何有害內容,並附有信心分數。
sensitive_information
任何與個人識別資訊(PII)或敏感資訊相關的檢測違規行為。
prompt_attack
偵測到的任何提示攻擊的陣列,附有信心分數。

常見錯誤

API 返回標準 HTTP 狀態碼:
  • 400 錯誤的請求:請檢查錯誤訊息以獲取詳細資訊
  • 403 禁止存取:使用者權限不足或驗證問題
  • 429 請求過多:超出速率限制
  • 500 內部伺服器錯誤:伺服器端發生暫時性問題

程式碼範例

請參閱以下範例程式碼,以整合 AI Guard 至不同語言中: