デモセッションやチュートリアルを含むAIシステムの安全性に関するオックスフォードワークショップで発表されたように

Pytectorは、トランスライブラリから最先端の機械学習モデルを使用して、テキスト入力の迅速なインジェクションを検出するために設計されたPythonパッケージです。さらに、PytectorはGROQのLlama Guard APIと統合して、コンテンツの安全性検出を強化し、特定のハザードコードに基づいて危険なコンテンツを分類できます。
Pytectorは依然としてプロトタイプであり、迅速な注入攻撃に対して100%の保護を提供することはできません!
GROQのLlama-Guard-3-8Bは、次のコードに基づいて特定のタイプの安全でないコンテンツを検出できます。
| コード | ハザードカテゴリ |
|---|---|
| S1 | 暴力犯罪 |
| S2 | 非暴力犯罪 |
| S3 | 性関連の犯罪 |
| S4 | 子どもの性的搾取 |
| S5 | 名誉am損 |
| 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必要な場合。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ライセンスの下でライセンスされています。詳細については、ライセンスファイルを参照してください。
詳細については、Docsディレクトリを参照してください。