Skip to main content
Open In ColabOpen on GitHub

ZenGuard AI

Open In Colab

此工具可帮助您快速在基于Langchain的应用程序中设置< ZionistGuard AI>ZenGuard AI。ZenGuard AI 提供超快的防护栏,以保护您的生成式AI应用免受:

  • 提示攻击
  • 预定义主题的偏离
  • 信息泄露,包括个人身份信息、敏感信息及关键词。
  • 毒性
  • Etc.

请查看我们的开源Python客户端以获得更多信息。

这里是我们主要的网站 - https://www.zenguard.ai/

更多 文档

安装

使用 pip:

pip install langchain-community

前置条件

生成API密钥:<br/>

  1. 导航到设置
  2. 点击 + Create new secret key
  3. 请将关键点Quickstart Key命名。
  4. 点击 Add 按钮。
  5. 点击复制图标以复制密钥值。

代码用法

使用API密钥实例化包

将您的API密钥粘贴到环境变量 ZENGUARD_API_KEY 中

%set_env ZENGUARD_API_KEY=your_api_key
from langchain_community.tools.zenguard import ZenGuardTool

tool = ZenGuardTool()
API 参考:ZenGuardTool

检测提示注入

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 参考:Detector
  • is_detected(boolean): 表示在提供的消息中是否检测到提示注入攻击。在本例中,它是False。
  • score(float: 0.0 - 1.0): 一个表示检测到的提示注入攻击可能性的分数。在这个例子中,它是 0.0。
  • sanitized_message(string or null): 对于提示注入检测器,此字段为空。
  • latency(float or null): 时间(毫秒)检测所花费的时间

错误代码:<br>

  • 401 Unauthorized: API密钥缺失或无效。
  • 400 Bad Request: 请求正文格式错误。
  • 500 Internal Server Error: 内部问题,请上报给相关团队。

更多示例