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許可獲得許可。有關詳細信息,請參見許可證文件。
有關更多詳細信息,請參閱文檔目錄。