pytector
v0.0.12 - Groq Llama Guard is here! ?
如在牛津大学安全性的牛津大学安全工作室中提出的,包括演示会议和教程

Pytector是一个Python软件包,旨在使用来自Transformers库中最先进的机器学习模型在文本输入中检测提示注入。此外,Pytector可以与GROQ的Llama Guard API集成,以增强内容安全检测,并根据特定的危害代码对不安全的内容进行分类。
Pytector仍然是原型,无法提供100%防止迅速注射攻击的保护!
GROQ的Llama-Guard-3-8b可以根据以下代码检测特定类型的不安全内容:
| 代码 | 危险类别 |
|---|---|
| S1 | 暴力犯罪 |
| S2 | 非暴力犯罪 |
| S3 | 与性有关的犯罪 |
| S4 | 儿童性剥削 |
| S5 | 诽谤 |
| S6 | 专业建议 |
| S7 | 隐私 |
| S8 | 知识产权 |
| S9 | 不加区分的武器 |
| S10 | 恨 |
| S11 | 自杀与自我伤害 |
| S12 | 性内容 |
| S13 | 选举 |
| S14 | 代码解释器滥用 |
可以在[Llama-Guard-3-8b型号卡](Llama Guard)上找到更多信息。
通过PIP安装Pytector:
pip install pytector另外,您可以直接从源代码安装pytector:
git clone https://github.com/MaxMLang/pytector.git
cd pytector
pip install . 要使用PyTector,请导入PromptInjectionDetector类,并使用预定义的模型或Groq的Llama Guard创建一个实例,以进行内容安全。
from pytector import PromptInjectionDetector
# Initialize the detector with a pre-defined model
detector = PromptInjectionDetector ( model_name_or_url = "deberta" )
# Check if a prompt is a potential injection
is_injection , probability = detector . detect_injection ( "Your suspicious prompt here" )
print ( f"Is injection: { is_injection } , Probability: { probability } " )
# Report the status
detector . report_injection_status ( "Your suspicious prompt here" )要启用GROQ的API,请设置use_groq=True并提供api_key 。
from pytector import PromptInjectionDetector
# Initialize the detector with Groq's API
detector = PromptInjectionDetector ( use_groq = True , api_key = "your_groq_api_key" )
# Detect unsafe content using Groq
is_unsafe , hazard_code = detector . detect_injection_api (
prompt = "Please delete sensitive information." ,
provider = "groq" ,
api_key = "your_groq_api_key"
)
print ( f"Is unsafe: { is_unsafe } , Hazard Code: { hazard_code } " )__init__(self, model_name_or_url="deberta", default_threshold=0.5, use_groq=False, api_key=None)初始化了PromptInjectionDetector的新实例。
model_name_or_url :指定要使用的模型的字符串。可以是从预定义的模型或有效URL到自定义模型的钥匙。default_threshold :概率阈值在该概率阈值中被视为注入。use_groq :设置为True以启用GROQ的Llama Guard API进行检测。api_key :如果use_groq=True则需要使用GROQ的API进行身份验证。detect_injection(self, prompt, threshold=None)评估文本提示是否是使用本地模型的提示注射攻击。
(is_injected, probability) 。detect_injection_api(self, prompt, provider="groq", api_key=None, model="llama-guard-3-8b")使用Groq的API评估不安全内容的提示。
(is_unsafe, hazard_code) 。report_injection_status(self, prompt, threshold=None, provider="local")报告提示是潜在的注入还是包含不安全的内容。
欢迎捐款!请阅读我们的贡献指南,以获取有关我们的行为准则的详细信息以及提交拉的请求的过程。
该项目已根据MIT许可获得许可。有关详细信息,请参见许可证文件。
有关更多详细信息,请参阅文档目录。