asofter commited on
Commit
0ccf7ba
1 Parent(s): 6aa9546

* upgrade transformers

Browse files

* make dataset private
* support azure benchmarks

Files changed (2) hide show
  1. app.py +21 -3
  2. requirements.txt +1 -1
app.py CHANGED
@@ -27,6 +27,8 @@ num_processes = 2 # mp.cpu_count()
27
  lakera_api_key = os.getenv("LAKERA_API_KEY")
28
  automorphic_api_key = os.getenv("AUTOMORPHIC_API_KEY")
29
  rebuff_api_key = os.getenv("REBUFF_API_KEY")
 
 
30
 
31
 
32
  @lru_cache(maxsize=2)
@@ -134,6 +136,22 @@ def detect_rebuff(prompt: str) -> (bool, bool):
134
  return False, False
135
 
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  detection_providers = {
138
  "Laiyer (HF model)": detect_hf_laiyer,
139
  "Deepset (HF model)": detect_hf_deepset,
@@ -141,6 +159,7 @@ detection_providers = {
141
  "Lakera Guard": detect_lakera,
142
  "Automorphic Aegis": detect_automorphic,
143
  "Rebuff": detect_rebuff,
 
144
  }
145
 
146
 
@@ -210,9 +229,8 @@ if __name__ == "__main__":
210
  ],
211
  title="Prompt Injection Benchmark",
212
  description="This interface aims to benchmark the prompt injection detection providers. "
213
- "The results are <strong>stored in the public dataset</strong> "
214
- '<a href="https://huggingface.co/datasets/laiyer/prompt-injection-benchmark" target="_blank">laiyer/prompt-injection-benchmark</a> '
215
- "for fairness of all sides.<br /><br />"
216
  "HuggingFace (HF) models are hosted on Spaces while other providers are called as APIs.<br /><br />"
217
  "<b>Disclaimer</b>: This interface is for research purposes only.",
218
  examples=[
 
27
  lakera_api_key = os.getenv("LAKERA_API_KEY")
28
  automorphic_api_key = os.getenv("AUTOMORPHIC_API_KEY")
29
  rebuff_api_key = os.getenv("REBUFF_API_KEY")
30
+ azure_content_safety_endpoint = os.getenv("AZURE_CONTENT_SAFETY_ENDPOINT")
31
+ azure_content_safety_key = os.getenv("AZURE_CONTENT_SAFETY_KEY")
32
 
33
 
34
  @lru_cache(maxsize=2)
 
136
  return False, False
137
 
138
 
139
+ def detect_azure(prompt: str) -> (bool, bool):
140
+ try:
141
+ response = requests.post(
142
+ f"{azure_content_safety_endpoint}contentsafety/text:detectJailbreak?api-version=2023-10-15-preview",
143
+ json={"text": prompt},
144
+ headers={"Ocp-Apim-Subscription-Key": azure_content_safety_key},
145
+ )
146
+ response_json = response.json()
147
+ logger.info(f"Prompt injection result from Azure: {response.json()}")
148
+
149
+ return True, response_json["jailbreakAnalysis"]["detected"]
150
+ except requests.RequestException as err:
151
+ logger.error(f"Failed to call Azure API: {err}")
152
+ return False, False
153
+
154
+
155
  detection_providers = {
156
  "Laiyer (HF model)": detect_hf_laiyer,
157
  "Deepset (HF model)": detect_hf_deepset,
 
159
  "Lakera Guard": detect_lakera,
160
  "Automorphic Aegis": detect_automorphic,
161
  "Rebuff": detect_rebuff,
162
+ "Azure Content Safety": detect_azure,
163
  }
164
 
165
 
 
229
  ],
230
  title="Prompt Injection Benchmark",
231
  description="This interface aims to benchmark the prompt injection detection providers. "
232
+ "The results are <strong>stored in the private dataset</strong> for further analysis and improvements."
233
+ "<br /><br />"
 
234
  "HuggingFace (HF) models are hosted on Spaces while other providers are called as APIs.<br /><br />"
235
  "<b>Disclaimer</b>: This interface is for research purposes only.",
236
  examples=[
requirements.txt CHANGED
@@ -5,4 +5,4 @@ onnxruntime==1.16.3
5
  optimum[onnxruntime]==1.15.0
6
  rebuff==0.0.5
7
  requests==2.31.0
8
- transformers==4.35.2
 
5
  optimum[onnxruntime]==1.15.0
6
  rebuff==0.0.5
7
  requests==2.31.0
8
+ transformers==4.36.0