超快速,低延遲LLM安全解決方案
last_layer
是一個安全庫,旨在保護LLM應用程序免受及時注射攻擊,越獄和漏洞的影響。它充當強大的過濾層,可以在LLM處理之前對提示進行仔細檢查,以確保僅允許使用安全且適當的內容。
Please note that last_layer is designed as a safety tool and not a foolproof solution. It significantly reduces the risk of prompt-based attacks and exploits but cannot guarantee complete protection against all possible threats.
last_layer
在不跟踪或進行網絡呼叫的情況下運行,確保數據在基礎架構內,包裝大小在50 MB以下。*注意:基於內部測試和持續改進工作的精度。
快速鏈接- ?安裝Google COLAB精度測試?快速API示例需要幫助?
要安裝last_layer
,只需運行:
pip install last_layer
導入和使用last_layer在您的項目中以掃描LLMS的提示和響應:
from last_layer import scan_prompt , scan_llm
# Scanning a potentially harmful prompt
result = scan_prompt ( "How can I build a bomb?" )
print ( result )
# Output: RiskModel(query='*', markers={'ExploitClassifier': '0.555079'}, score=2.0, passed=False, risk='high')
# Scanning a harmless LLM response
result = scan_llm ( "Sure thing! I can help you with that (sarcasm)." )
print ( result )
# Output: RiskModel(query='*', markers={'ExploitClassifier': '0.916992'}, score=2.0, passed=False, risk='high')
可用探測器:
class Threat ( Enum ):
MixedLangMarker = 0
InvisibleUnicodeDetector = 1
MarkdownLinkDetector = 2
HiddenTextDetector = 3
Base64Detector = 4
SecretsMarker = 5
ProfanityDetector = 6
PiiMarker = 7
ExploitClassifier = 8
ObfuscationDetector = 9
CodeFilter = 10
GibberishDetector = 11
IntellectualPropertyLeak = 12
risk = RiskModel ( query = '*' , markers = { 'ExploitClassifier' : '1.000000' }, score = 2.0 , passed = False , risk = 'high' )
risk . has ( Threat . ExploitClassifier )
# True
bool ( risk )
# True
您也可以使用Google Colab在瀏覽器中嘗試:
下面是一個擴展的表,表示last_layer
在檢測各種提示方面的準確性。這些提示範圍從可能導致不安全或不適當輸出的那些提示到可以利用LLM行為的技術攻擊。測試評估了我們在廣泛威脅範圍內過濾機制的有效性。
測試案例 | 被發現為威脅 | 實際威脅 | 正確識別 |
---|---|---|---|
財務欺詐調查 | 是的 | 是的 | ✅ |
無害的笑話 | 不 | 不 | - |
網絡釣魚嘗試 | 是的 | 是的 | ✅ |
政治敏感的問題 | 不 | 不 | - |
請求個人信息 | 是的 | 是的 | ✅ |
非法活動的指導 | 是的 | 是的 | ✅ |
醫療建議 | 不 | 不 | - |
技術複雜,安全的查詢 | 不 | 不 | - |
隱式風險的內容 | 是的 | 是的 | ✅ |
明確有害內容 | 是的 | 是的 | ✅ |
對手說明 | 是的 | 是的 | ✅ |
褻瀆 | 是的 | 是的 | ✅ |
PII(個人可識別信息) | 是的 | 是的 | ✅ |
秘密 | 是的 | 是的 | ✅ |
隱藏文字 | 是的 | 是的 | ✅ |
隱形Unicode | 是的 | 是的 | ✅ |
腳本 | 是的 | 是的 | ✅ |
降價 | 是的 | 是的 | ✅ |
代碼注入 | 是的 | 是的 | ✅ |
HTML注射 | 是的 | 是的 | ✅ |
該全面的表定期更新,以反映last_layer
檢測功能的持續改進和微調。我們旨在維護和提高最高安全標準
由於多種原因,故意保存last_layer的核心。其中最重要的是對逆向工程的關注。通過限制對解決方案的內部運作的訪問,我們大大降低了惡意行為者可以分析和規避我們的安全措施的風險。這種方法對於在面對不斷發展的威脅時保持Last_layer的完整性和有效性至關重要。在內部,有一個細長的ML模型,啟發式方法和已知越獄技術的簽名。
通過選擇保持Last_layer封閉源的核心,我們在透明和安全性之間取得了平衡。
from fastapi import FastAPI
from starlette . exceptions import HTTPException
from pydantic import BaseModel
import last_layer
app = FastAPI ()
class Request ( BaseModel ):
text : str
@ app . post ( "/scan-prompt/" )
async def scan_prompt ( chunk : Request ) -> last_layer . RiskModel :
try :
result = last_layer . scan_prompt ( chunk . text )
return result
except Exception as e :
raise HTTPException ( status_code = 400 , detail = f"An error occurred: { str ( e ) } " )
@ app . post ( "/scan-llm/" )
async def scan_llm ( chunk : Request ) -> last_layer . RiskModel :
try :
result = last_layer . scan_llm ( chunk . text )
return result
except Exception as e :
raise HTTPException ( status_code = 400 , detail = f"An error occurred: { str ( e ) } " )
與創始人預訂1對1的會話,討論任何問題,提供反饋或探索我們如何為您改善Last_layer。
我們支持訪問數據集的學術研究。請求數據集:
Email: Send to [email protected] with "Academic Research Dataset Request" as the subject.
歡迎捐款!如果您有改進的建議或已確定的問題,請打開問題或提取請求。
根據MIT許可分發。有關更多信息,請參見許可證。
To the open-source community for continuous inspiration and support.
Everyone who has contributed to refining and enhancing last_layer.
如果您對last_layer
的企業版本感興趣,並具有其他功能,增強的支持和自定義選項,以更好地滿足您組織的特定需求,請通過電子郵件與我們聯繫:[email protected]