데모 세션 및 튜토리얼을 포함한 AI 시스템의 안전에 관한 옥스포드 워크숍에서 발표 된 바와 같이

Pytector 는 Transformers 라이브러리의 최첨단 머신 러닝 모델을 사용하여 텍스트 입력에서 신속한 주입을 감지하도록 설계된 Python 패키지입니다. 또한 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 가드로 인스턴스를 만듭니다.
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 : GROQ의 LLAMA 가드 API를 탐지 할 수 있도록 True 로 설정하십시오.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 라이센스에 따라 라이센스가 부여됩니다. 자세한 내용은 라이센스 파일을 참조하십시오.
자세한 내용은 문서 디렉토리를 참조하십시오.