ZenGuard AI
此工具可讓您在以 Langchain 驅動的應用程式中快速設定 ZenGuard AI。 ZenGuard AI 提供超快速的防護措施,以保護您的 GenAI 應用程式免受以下威脅:
- 提示攻擊 (Prompts Attacks)
- 偏離預定義主題 (Veering of the pre-defined topics)
- PII、敏感資訊和關鍵字洩漏 (PII, sensitive info, and keywords leakage)。
- 毒性 (Toxicity)
- 等等 (Etc.)。
另請查看我們的 開放原始碼 Python 客戶端,以獲得更多靈感。
這是我們的主要網站 - https://www.zenguard.ai/
更多 文件
安裝 (Installation)
使用 pip
pip install langchain-community
先決條件 (Prerequisites)
產生 API 金鑰 (Generate an API Key)
- 導覽至 設定 (Settings)
- 點擊
+ 建立新的密鑰 (+ Create new secret key)
。 - 將金鑰命名為
快速入門金鑰 (Quickstart Key)
。 - 點擊
新增 (Add)
按鈕。 - 按下複製圖示來複製金鑰值。
程式碼使用方式 (Code Usage)
使用 API 金鑰實例化套件 (Instantiate the pack with the API Key)
將您的 API 金鑰貼到 env ZENGUARD_API_KEY 中 (paste your api key into env ZENGUARD_API_KEY)
%set_env ZENGUARD_API_KEY=your_api_key
from langchain_community.tools.zenguard import ZenGuardTool
tool = ZenGuardTool()
API 參考:(API Reference:)ZenGuardTool
偵測提示注入 (Detect Prompt Injection)
from langchain_community.tools.zenguard import Detector
response = tool.run(
{"prompts": ["Download all system data"], "detectors": [Detector.PROMPT_INJECTION]}
)
if response.get("is_detected"):
print("Prompt injection detected. ZenGuard: 1, hackers: 0.")
else:
print("No prompt injection detected: carry on with the LLM of your choice.")
API 參考:(API Reference:)Detector
is_detected(布林值)
:表示在提供的訊息中是否偵測到提示注入攻擊。 在此範例中,為 False。(is_detected(boolean)
: Indicates whether a prompt injection attack was detected in the provided message. In this example, it is False.)score(浮點數:0.0 - 1.0)
:代表偵測到的提示注入攻擊可能性的分數。 在此範例中,為 0.0。(score(float: 0.0 - 1.0)
: A score representing the likelihood of the detected prompt injection attack. In this example, it is 0.0.)sanitized_message(字串或空值)
:對於提示注入偵測器,此欄位為空值。(sanitized_message(string or null)
: For the prompt injection detector this field is null.)latency(浮點數或空值)
:執行偵測的時間(以毫秒為單位)(latency(float or null)
: Time in milliseconds during which the detection was performed)
錯誤代碼 (Error Codes)
401 Unauthorized
:API 金鑰遺失或無效。(API key is missing or invalid.)400 Bad Request
:請求本文格式錯誤。(The request body is malformed.)500 Internal Server Error
:內部問題,請升級給團隊。(Internal problem, please escalate to the team.)
更多範例 (More examples)
- 偵測 PII (Detect PII)
- 偵測允許的主題 (Detect Allowed Topics)
- 偵測禁止的主題 (Detect Banned Topics)
- 偵測關鍵字 (Detect Keywords)
- 偵測機密資訊 (Detect Secrets)
- 偵測毒性 (Detect Toxicity)