* upgrade version of llm-guard with new features
Browse files- Dockerfile +0 -1
- app.py +0 -4
- output.py +137 -8
- prompt.py +147 -2
- prompt_text.txt +9 -9
- requirements.txt +2 -1
Dockerfile
CHANGED
@@ -12,7 +12,6 @@ COPY ./requirements.txt /app/requirements.txt
|
|
12 |
|
13 |
RUN pip install --upgrade pip
|
14 |
RUN pip install -r requirements.txt
|
15 |
-
RUN python -m spacy download en_core_web_trf
|
16 |
|
17 |
EXPOSE 7860
|
18 |
|
|
|
12 |
|
13 |
RUN pip install --upgrade pip
|
14 |
RUN pip install -r requirements.txt
|
|
|
15 |
|
16 |
EXPOSE 7860
|
17 |
|
app.py
CHANGED
@@ -4,7 +4,6 @@ import traceback
|
|
4 |
from datetime import timedelta
|
5 |
|
6 |
import pandas as pd
|
7 |
-
import spacy
|
8 |
import streamlit as st
|
9 |
from output import init_settings as init_output_settings
|
10 |
from output import scan as scan_output
|
@@ -13,9 +12,6 @@ from prompt import scan as scan_prompt
|
|
13 |
|
14 |
from llm_guard.vault import Vault
|
15 |
|
16 |
-
if not spacy.util.is_package("en_core_web_trf"):
|
17 |
-
spacy.cli.download("en_core_web_trf")
|
18 |
-
|
19 |
PROMPT = "prompt"
|
20 |
OUTPUT = "output"
|
21 |
vault = Vault()
|
|
|
4 |
from datetime import timedelta
|
5 |
|
6 |
import pandas as pd
|
|
|
7 |
import streamlit as st
|
8 |
from output import init_settings as init_output_settings
|
9 |
from output import scan as scan_output
|
|
|
12 |
|
13 |
from llm_guard.vault import Vault
|
14 |
|
|
|
|
|
|
|
15 |
PROMPT = "prompt"
|
16 |
OUTPUT = "output"
|
17 |
vault = Vault()
|
output.py
CHANGED
@@ -6,11 +6,14 @@ from streamlit_tags import st_tags
|
|
6 |
|
7 |
from llm_guard.input_scanners.anonymize import default_entity_types
|
8 |
from llm_guard.output_scanners import (
|
|
|
9 |
BanSubstrings,
|
10 |
BanTopics,
|
11 |
Bias,
|
12 |
Code,
|
13 |
Deanonymize,
|
|
|
|
|
14 |
MaliciousURLs,
|
15 |
NoRefusal,
|
16 |
Refutation,
|
@@ -18,6 +21,7 @@ from llm_guard.output_scanners import (
|
|
18 |
Relevance,
|
19 |
Sensitive,
|
20 |
)
|
|
|
21 |
from llm_guard.output_scanners.sentiment import Sentiment
|
22 |
from llm_guard.output_scanners.toxicity import Toxicity
|
23 |
from llm_guard.vault import Vault
|
@@ -32,6 +36,9 @@ def init_settings() -> (List, Dict):
|
|
32 |
"Bias",
|
33 |
"Code",
|
34 |
"Deanonymize",
|
|
|
|
|
|
|
35 |
"MaliciousURLs",
|
36 |
"NoRefusal",
|
37 |
"Refutation",
|
@@ -67,12 +74,14 @@ def init_settings() -> (List, Dict):
|
|
67 |
st_bs_match_type = st.selectbox("Match type", ["str", "word"])
|
68 |
st_bs_case_sensitive = st.checkbox("Case sensitive", value=False)
|
69 |
st_bs_redact = st.checkbox("Redact", value=False)
|
|
|
70 |
|
71 |
settings["BanSubstrings"] = {
|
72 |
"substrings": st_bs_substrings,
|
73 |
"match_type": st_bs_match_type,
|
74 |
"case_sensitive": st_bs_case_sensitive,
|
75 |
"redact": st_bs_redact,
|
|
|
76 |
}
|
77 |
|
78 |
if "BanTopics" in st_enabled_scanners:
|
@@ -85,7 +94,7 @@ def init_settings() -> (List, Dict):
|
|
85 |
st_bt_topics = st_tags(
|
86 |
label="List of topics",
|
87 |
text="Type and press enter",
|
88 |
-
value=["
|
89 |
suggestions=[],
|
90 |
maxtags=30,
|
91 |
key="bt_topics",
|
@@ -93,7 +102,7 @@ def init_settings() -> (List, Dict):
|
|
93 |
|
94 |
st_bt_threshold = st.slider(
|
95 |
label="Threshold",
|
96 |
-
value=0.
|
97 |
min_value=0.0,
|
98 |
max_value=1.0,
|
99 |
step=0.05,
|
@@ -137,6 +146,98 @@ def init_settings() -> (List, Dict):
|
|
137 |
|
138 |
settings["Code"] = {"languages": st_cd_languages, "mode": st_cd_mode}
|
139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
if "MaliciousURLs" in st_enabled_scanners:
|
141 |
st_murls_expander = st.sidebar.expander(
|
142 |
"Malicious URLs",
|
@@ -231,14 +332,15 @@ def init_settings() -> (List, Dict):
|
|
231 |
st_rele_threshold = st.slider(
|
232 |
label="Threshold",
|
233 |
value=0.5,
|
234 |
-
min_value
|
235 |
max_value=1.0,
|
236 |
step=0.05,
|
237 |
key="rele_threshold",
|
238 |
-
help="The minimum cosine similarity (-1 to 1) between the prompt and output for the output to be considered relevant.",
|
239 |
)
|
240 |
|
241 |
-
|
|
|
|
|
242 |
|
243 |
if "Sensitive" in st_enabled_scanners:
|
244 |
st_sens_expander = st.sidebar.expander(
|
@@ -259,8 +361,21 @@ def init_settings() -> (List, Dict):
|
|
259 |
st.caption(
|
260 |
"Check all supported entities: https://microsoft.github.io/presidio/supported_entities/#list-of-supported-entities"
|
261 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
|
263 |
-
settings["Sensitive"] = {
|
|
|
|
|
|
|
|
|
264 |
|
265 |
if "Sentiment" in st_enabled_scanners:
|
266 |
st_sent_expander = st.sidebar.expander(
|
@@ -312,6 +427,7 @@ def get_scanner(scanner_name: str, vault: Vault, settings: Dict):
|
|
312 |
match_type=settings["match_type"],
|
313 |
case_sensitive=settings["case_sensitive"],
|
314 |
redact=settings["redact"],
|
|
|
315 |
)
|
316 |
|
317 |
if scanner_name == "BanTopics":
|
@@ -323,6 +439,15 @@ def get_scanner(scanner_name: str, vault: Vault, settings: Dict):
|
|
323 |
if scanner_name == "Deanonymize":
|
324 |
return Deanonymize(vault=vault)
|
325 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
326 |
if scanner_name == "Code":
|
327 |
mode = settings["mode"]
|
328 |
|
@@ -359,10 +484,14 @@ def get_scanner(scanner_name: str, vault: Vault, settings: Dict):
|
|
359 |
)
|
360 |
|
361 |
if scanner_name == "Relevance":
|
362 |
-
return Relevance(threshold=settings["threshold"])
|
363 |
|
364 |
if scanner_name == "Sensitive":
|
365 |
-
return Sensitive(
|
|
|
|
|
|
|
|
|
366 |
|
367 |
if scanner_name == "Sentiment":
|
368 |
return Sentiment(threshold=settings["threshold"])
|
|
|
6 |
|
7 |
from llm_guard.input_scanners.anonymize import default_entity_types
|
8 |
from llm_guard.output_scanners import (
|
9 |
+
JSON,
|
10 |
BanSubstrings,
|
11 |
BanTopics,
|
12 |
Bias,
|
13 |
Code,
|
14 |
Deanonymize,
|
15 |
+
Language,
|
16 |
+
LanguageSame,
|
17 |
MaliciousURLs,
|
18 |
NoRefusal,
|
19 |
Refutation,
|
|
|
21 |
Relevance,
|
22 |
Sensitive,
|
23 |
)
|
24 |
+
from llm_guard.output_scanners.relevance import all_models as relevance_models
|
25 |
from llm_guard.output_scanners.sentiment import Sentiment
|
26 |
from llm_guard.output_scanners.toxicity import Toxicity
|
27 |
from llm_guard.vault import Vault
|
|
|
36 |
"Bias",
|
37 |
"Code",
|
38 |
"Deanonymize",
|
39 |
+
"JSON",
|
40 |
+
"Language",
|
41 |
+
"LanguageSame",
|
42 |
"MaliciousURLs",
|
43 |
"NoRefusal",
|
44 |
"Refutation",
|
|
|
74 |
st_bs_match_type = st.selectbox("Match type", ["str", "word"])
|
75 |
st_bs_case_sensitive = st.checkbox("Case sensitive", value=False)
|
76 |
st_bs_redact = st.checkbox("Redact", value=False)
|
77 |
+
st_bs_contains_all = st.checkbox("Contains all", value=False)
|
78 |
|
79 |
settings["BanSubstrings"] = {
|
80 |
"substrings": st_bs_substrings,
|
81 |
"match_type": st_bs_match_type,
|
82 |
"case_sensitive": st_bs_case_sensitive,
|
83 |
"redact": st_bs_redact,
|
84 |
+
"contains_all": st_bs_contains_all,
|
85 |
}
|
86 |
|
87 |
if "BanTopics" in st_enabled_scanners:
|
|
|
94 |
st_bt_topics = st_tags(
|
95 |
label="List of topics",
|
96 |
text="Type and press enter",
|
97 |
+
value=["violence"],
|
98 |
suggestions=[],
|
99 |
maxtags=30,
|
100 |
key="bt_topics",
|
|
|
102 |
|
103 |
st_bt_threshold = st.slider(
|
104 |
label="Threshold",
|
105 |
+
value=0.6,
|
106 |
min_value=0.0,
|
107 |
max_value=1.0,
|
108 |
step=0.05,
|
|
|
146 |
|
147 |
settings["Code"] = {"languages": st_cd_languages, "mode": st_cd_mode}
|
148 |
|
149 |
+
if "JSON" in st_enabled_scanners:
|
150 |
+
st_json_expander = st.sidebar.expander(
|
151 |
+
"JSON",
|
152 |
+
expanded=False,
|
153 |
+
)
|
154 |
+
|
155 |
+
with st_json_expander:
|
156 |
+
st_json_required_elements = st.slider(
|
157 |
+
label="Required elements",
|
158 |
+
value=0,
|
159 |
+
min_value=0,
|
160 |
+
max_value=10,
|
161 |
+
step=1,
|
162 |
+
key="json_required_elements",
|
163 |
+
help="The minimum number of JSON elements that should be present",
|
164 |
+
)
|
165 |
+
|
166 |
+
settings["JSON"] = {"required_elements": st_json_required_elements}
|
167 |
+
|
168 |
+
if "Language" in st_enabled_scanners:
|
169 |
+
st_lan_expander = st.sidebar.expander(
|
170 |
+
"Language",
|
171 |
+
expanded=False,
|
172 |
+
)
|
173 |
+
|
174 |
+
with st_lan_expander:
|
175 |
+
st_lan_valid_language = st.multiselect(
|
176 |
+
"Languages",
|
177 |
+
[
|
178 |
+
"af",
|
179 |
+
"ar",
|
180 |
+
"bg",
|
181 |
+
"bn",
|
182 |
+
"ca",
|
183 |
+
"cs",
|
184 |
+
"cy",
|
185 |
+
"da",
|
186 |
+
"de",
|
187 |
+
"el",
|
188 |
+
"en",
|
189 |
+
"es",
|
190 |
+
"et",
|
191 |
+
"fa",
|
192 |
+
"fi",
|
193 |
+
"fr",
|
194 |
+
"gu",
|
195 |
+
"he",
|
196 |
+
"hi",
|
197 |
+
"hr",
|
198 |
+
"hu",
|
199 |
+
"id",
|
200 |
+
"it",
|
201 |
+
"ja",
|
202 |
+
"kn",
|
203 |
+
"ko",
|
204 |
+
"lt",
|
205 |
+
"lv",
|
206 |
+
"mk",
|
207 |
+
"ml",
|
208 |
+
"mr",
|
209 |
+
"ne",
|
210 |
+
"nl",
|
211 |
+
"no",
|
212 |
+
"pa",
|
213 |
+
"pl",
|
214 |
+
"pt",
|
215 |
+
"ro",
|
216 |
+
"ru",
|
217 |
+
"sk",
|
218 |
+
"sl",
|
219 |
+
"so",
|
220 |
+
"sq",
|
221 |
+
"sv",
|
222 |
+
"sw",
|
223 |
+
"ta",
|
224 |
+
"te",
|
225 |
+
"th",
|
226 |
+
"tl",
|
227 |
+
"tr",
|
228 |
+
"uk",
|
229 |
+
"ur",
|
230 |
+
"vi",
|
231 |
+
"zh-cn",
|
232 |
+
"zh-tw",
|
233 |
+
],
|
234 |
+
default=["en"],
|
235 |
+
)
|
236 |
+
|
237 |
+
settings["Language"] = {
|
238 |
+
"valid_languages": st_lan_valid_language,
|
239 |
+
}
|
240 |
+
|
241 |
if "MaliciousURLs" in st_enabled_scanners:
|
242 |
st_murls_expander = st.sidebar.expander(
|
243 |
"Malicious URLs",
|
|
|
332 |
st_rele_threshold = st.slider(
|
333 |
label="Threshold",
|
334 |
value=0.5,
|
335 |
+
min_value=0.0,
|
336 |
max_value=1.0,
|
337 |
step=0.05,
|
338 |
key="rele_threshold",
|
|
|
339 |
)
|
340 |
|
341 |
+
st_rele_model = st.selectbox("Embeddings model", relevance_models, index=1)
|
342 |
+
|
343 |
+
settings["Relevance"] = {"threshold": st_rele_threshold, "model": st_rele_model}
|
344 |
|
345 |
if "Sensitive" in st_enabled_scanners:
|
346 |
st_sens_expander = st.sidebar.expander(
|
|
|
361 |
st.caption(
|
362 |
"Check all supported entities: https://microsoft.github.io/presidio/supported_entities/#list-of-supported-entities"
|
363 |
)
|
364 |
+
st_sens_redact = st.checkbox("Redact", value=False)
|
365 |
+
st_sens_threshold = st.slider(
|
366 |
+
label="Threshold",
|
367 |
+
value=0,
|
368 |
+
min_value=0.0,
|
369 |
+
max_value=1.0,
|
370 |
+
step=0.1,
|
371 |
+
key="sens_threshold",
|
372 |
+
)
|
373 |
|
374 |
+
settings["Sensitive"] = {
|
375 |
+
"entity_types": st_sens_entity_types,
|
376 |
+
"redact": st_sens_redact,
|
377 |
+
"threshold": st_sens_threshold,
|
378 |
+
}
|
379 |
|
380 |
if "Sentiment" in st_enabled_scanners:
|
381 |
st_sent_expander = st.sidebar.expander(
|
|
|
427 |
match_type=settings["match_type"],
|
428 |
case_sensitive=settings["case_sensitive"],
|
429 |
redact=settings["redact"],
|
430 |
+
contains_all=settings["contains_all"],
|
431 |
)
|
432 |
|
433 |
if scanner_name == "BanTopics":
|
|
|
439 |
if scanner_name == "Deanonymize":
|
440 |
return Deanonymize(vault=vault)
|
441 |
|
442 |
+
if scanner_name == "JSON":
|
443 |
+
return JSON(required_elements=settings["required_elements"])
|
444 |
+
|
445 |
+
if scanner_name == "Language":
|
446 |
+
return Language(valid_languages=settings["valid_languages"])
|
447 |
+
|
448 |
+
if scanner_name == "LanguageSame":
|
449 |
+
return LanguageSame()
|
450 |
+
|
451 |
if scanner_name == "Code":
|
452 |
mode = settings["mode"]
|
453 |
|
|
|
484 |
)
|
485 |
|
486 |
if scanner_name == "Relevance":
|
487 |
+
return Relevance(threshold=settings["threshold"], model=settings["model"])
|
488 |
|
489 |
if scanner_name == "Sensitive":
|
490 |
+
return Sensitive(
|
491 |
+
entity_types=settings["entity_types"],
|
492 |
+
redact=settings["redact"],
|
493 |
+
threshold=settings["threshold"],
|
494 |
+
)
|
495 |
|
496 |
if scanner_name == "Sentiment":
|
497 |
return Sentiment(threshold=settings["threshold"])
|
prompt.py
CHANGED
@@ -9,14 +9,17 @@ from llm_guard.input_scanners import (
|
|
9 |
BanSubstrings,
|
10 |
BanTopics,
|
11 |
Code,
|
|
|
12 |
PromptInjection,
|
13 |
PromptInjectionV2,
|
|
|
14 |
Secrets,
|
15 |
Sentiment,
|
16 |
TokenLimit,
|
17 |
Toxicity,
|
18 |
)
|
19 |
from llm_guard.input_scanners.anonymize import default_entity_types
|
|
|
20 |
from llm_guard.vault import Vault
|
21 |
|
22 |
logger = logging.getLogger("llm-guard-playground")
|
@@ -28,8 +31,10 @@ def init_settings() -> (List, Dict):
|
|
28 |
"BanSubstrings",
|
29 |
"BanTopics",
|
30 |
"Code",
|
|
|
31 |
"PromptInjection",
|
32 |
"PromptInjectionV2",
|
|
|
33 |
"Secrets",
|
34 |
"Sentiment",
|
35 |
"TokenLimit",
|
@@ -88,6 +93,19 @@ def init_settings() -> (List, Dict):
|
|
88 |
st_anon_use_faker = st.checkbox(
|
89 |
"Use Faker", value=False, help="Use Faker library to generate fake data"
|
90 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
settings["Anonymize"] = {
|
93 |
"entity_types": st_anon_entity_types,
|
@@ -95,6 +113,8 @@ def init_settings() -> (List, Dict):
|
|
95 |
"allowed_names": st_anon_allowed_names,
|
96 |
"preamble": st_anon_preamble,
|
97 |
"use_faker": st_anon_use_faker,
|
|
|
|
|
98 |
}
|
99 |
|
100 |
if "BanSubstrings" in st_enabled_scanners:
|
@@ -113,12 +133,14 @@ def init_settings() -> (List, Dict):
|
|
113 |
st_bs_match_type = st.selectbox("Match type", ["str", "word"])
|
114 |
st_bs_case_sensitive = st.checkbox("Case sensitive", value=False)
|
115 |
st_bs_redact = st.checkbox("Redact", value=False)
|
|
|
116 |
|
117 |
settings["BanSubstrings"] = {
|
118 |
"substrings": st_bs_substrings,
|
119 |
"match_type": st_bs_match_type,
|
120 |
"case_sensitive": st_bs_case_sensitive,
|
121 |
"redact": st_bs_redact,
|
|
|
122 |
}
|
123 |
|
124 |
if "BanTopics" in st_enabled_scanners:
|
@@ -131,7 +153,7 @@ def init_settings() -> (List, Dict):
|
|
131 |
st_bt_topics = st_tags(
|
132 |
label="List of topics",
|
133 |
text="Type and press enter",
|
134 |
-
value=["
|
135 |
suggestions=[],
|
136 |
maxtags=30,
|
137 |
key="bt_topics",
|
@@ -139,7 +161,7 @@ def init_settings() -> (List, Dict):
|
|
139 |
|
140 |
st_bt_threshold = st.slider(
|
141 |
label="Threshold",
|
142 |
-
value=0.
|
143 |
min_value=0.0,
|
144 |
max_value=1.0,
|
145 |
step=0.05,
|
@@ -171,6 +193,79 @@ def init_settings() -> (List, Dict):
|
|
171 |
"mode": st_cd_mode,
|
172 |
}
|
173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
if "PromptInjection" in st_enabled_scanners:
|
175 |
st_pi_expander = st.sidebar.expander(
|
176 |
"Prompt Injection",
|
@@ -211,6 +306,36 @@ def init_settings() -> (List, Dict):
|
|
211 |
"threshold": st_piv2_threshold,
|
212 |
}
|
213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
if "Secrets" in st_enabled_scanners:
|
215 |
st_sec_expander = st.sidebar.expander(
|
216 |
"Secrets",
|
@@ -301,6 +426,8 @@ def get_scanner(scanner_name: str, vault: Vault, settings: Dict):
|
|
301 |
entity_types=settings["entity_types"],
|
302 |
preamble=settings["preamble"],
|
303 |
use_faker=settings["use_faker"],
|
|
|
|
|
304 |
)
|
305 |
|
306 |
if scanner_name == "BanSubstrings":
|
@@ -309,6 +436,7 @@ def get_scanner(scanner_name: str, vault: Vault, settings: Dict):
|
|
309 |
match_type=settings["match_type"],
|
310 |
case_sensitive=settings["case_sensitive"],
|
311 |
redact=settings["redact"],
|
|
|
312 |
)
|
313 |
|
314 |
if scanner_name == "BanTopics":
|
@@ -326,12 +454,29 @@ def get_scanner(scanner_name: str, vault: Vault, settings: Dict):
|
|
326 |
|
327 |
return Code(allowed=allowed_languages, denied=denied_languages)
|
328 |
|
|
|
|
|
|
|
329 |
if scanner_name == "PromptInjection":
|
330 |
return PromptInjection(threshold=settings["threshold"])
|
331 |
|
332 |
if scanner_name == "PromptInjectionV2":
|
333 |
return PromptInjectionV2(threshold=settings["threshold"])
|
334 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
335 |
if scanner_name == "Secrets":
|
336 |
return Secrets(redact_mode=settings["redact_mode"])
|
337 |
|
|
|
9 |
BanSubstrings,
|
10 |
BanTopics,
|
11 |
Code,
|
12 |
+
Language,
|
13 |
PromptInjection,
|
14 |
PromptInjectionV2,
|
15 |
+
Regex,
|
16 |
Secrets,
|
17 |
Sentiment,
|
18 |
TokenLimit,
|
19 |
Toxicity,
|
20 |
)
|
21 |
from llm_guard.input_scanners.anonymize import default_entity_types
|
22 |
+
from llm_guard.input_scanners.anonymize_helpers.analyzer import allowed_recognizers
|
23 |
from llm_guard.vault import Vault
|
24 |
|
25 |
logger = logging.getLogger("llm-guard-playground")
|
|
|
31 |
"BanSubstrings",
|
32 |
"BanTopics",
|
33 |
"Code",
|
34 |
+
"Language",
|
35 |
"PromptInjection",
|
36 |
"PromptInjectionV2",
|
37 |
+
"Regex",
|
38 |
"Secrets",
|
39 |
"Sentiment",
|
40 |
"TokenLimit",
|
|
|
93 |
st_anon_use_faker = st.checkbox(
|
94 |
"Use Faker", value=False, help="Use Faker library to generate fake data"
|
95 |
)
|
96 |
+
st_anon_threshold = st.slider(
|
97 |
+
label="Threshold",
|
98 |
+
value=0,
|
99 |
+
min_value=0.0,
|
100 |
+
max_value=1.0,
|
101 |
+
step=0.1,
|
102 |
+
key="anon_threshold",
|
103 |
+
)
|
104 |
+
st_anon_recognizer = st.selectbox(
|
105 |
+
"Recognizer",
|
106 |
+
allowed_recognizers,
|
107 |
+
index=1,
|
108 |
+
)
|
109 |
|
110 |
settings["Anonymize"] = {
|
111 |
"entity_types": st_anon_entity_types,
|
|
|
113 |
"allowed_names": st_anon_allowed_names,
|
114 |
"preamble": st_anon_preamble,
|
115 |
"use_faker": st_anon_use_faker,
|
116 |
+
"threshold": st_anon_threshold,
|
117 |
+
"recognizer": st_anon_recognizer,
|
118 |
}
|
119 |
|
120 |
if "BanSubstrings" in st_enabled_scanners:
|
|
|
133 |
st_bs_match_type = st.selectbox("Match type", ["str", "word"])
|
134 |
st_bs_case_sensitive = st.checkbox("Case sensitive", value=False)
|
135 |
st_bs_redact = st.checkbox("Redact", value=False)
|
136 |
+
st_bs_contains_all = st.checkbox("Contains all", value=False)
|
137 |
|
138 |
settings["BanSubstrings"] = {
|
139 |
"substrings": st_bs_substrings,
|
140 |
"match_type": st_bs_match_type,
|
141 |
"case_sensitive": st_bs_case_sensitive,
|
142 |
"redact": st_bs_redact,
|
143 |
+
"contains_all": st_bs_contains_all,
|
144 |
}
|
145 |
|
146 |
if "BanTopics" in st_enabled_scanners:
|
|
|
153 |
st_bt_topics = st_tags(
|
154 |
label="List of topics",
|
155 |
text="Type and press enter",
|
156 |
+
value=["violence"],
|
157 |
suggestions=[],
|
158 |
maxtags=30,
|
159 |
key="bt_topics",
|
|
|
161 |
|
162 |
st_bt_threshold = st.slider(
|
163 |
label="Threshold",
|
164 |
+
value=0.6,
|
165 |
min_value=0.0,
|
166 |
max_value=1.0,
|
167 |
step=0.05,
|
|
|
193 |
"mode": st_cd_mode,
|
194 |
}
|
195 |
|
196 |
+
if "Language" in st_enabled_scanners:
|
197 |
+
st_lan_expander = st.sidebar.expander(
|
198 |
+
"Language",
|
199 |
+
expanded=False,
|
200 |
+
)
|
201 |
+
|
202 |
+
with st_lan_expander:
|
203 |
+
st_lan_valid_language = st.multiselect(
|
204 |
+
"Languages",
|
205 |
+
[
|
206 |
+
"af",
|
207 |
+
"ar",
|
208 |
+
"bg",
|
209 |
+
"bn",
|
210 |
+
"ca",
|
211 |
+
"cs",
|
212 |
+
"cy",
|
213 |
+
"da",
|
214 |
+
"de",
|
215 |
+
"el",
|
216 |
+
"en",
|
217 |
+
"es",
|
218 |
+
"et",
|
219 |
+
"fa",
|
220 |
+
"fi",
|
221 |
+
"fr",
|
222 |
+
"gu",
|
223 |
+
"he",
|
224 |
+
"hi",
|
225 |
+
"hr",
|
226 |
+
"hu",
|
227 |
+
"id",
|
228 |
+
"it",
|
229 |
+
"ja",
|
230 |
+
"kn",
|
231 |
+
"ko",
|
232 |
+
"lt",
|
233 |
+
"lv",
|
234 |
+
"mk",
|
235 |
+
"ml",
|
236 |
+
"mr",
|
237 |
+
"ne",
|
238 |
+
"nl",
|
239 |
+
"no",
|
240 |
+
"pa",
|
241 |
+
"pl",
|
242 |
+
"pt",
|
243 |
+
"ro",
|
244 |
+
"ru",
|
245 |
+
"sk",
|
246 |
+
"sl",
|
247 |
+
"so",
|
248 |
+
"sq",
|
249 |
+
"sv",
|
250 |
+
"sw",
|
251 |
+
"ta",
|
252 |
+
"te",
|
253 |
+
"th",
|
254 |
+
"tl",
|
255 |
+
"tr",
|
256 |
+
"uk",
|
257 |
+
"ur",
|
258 |
+
"vi",
|
259 |
+
"zh-cn",
|
260 |
+
"zh-tw",
|
261 |
+
],
|
262 |
+
default=["en"],
|
263 |
+
)
|
264 |
+
|
265 |
+
settings["Language"] = {
|
266 |
+
"valid_languages": st_lan_valid_language,
|
267 |
+
}
|
268 |
+
|
269 |
if "PromptInjection" in st_enabled_scanners:
|
270 |
st_pi_expander = st.sidebar.expander(
|
271 |
"Prompt Injection",
|
|
|
306 |
"threshold": st_piv2_threshold,
|
307 |
}
|
308 |
|
309 |
+
if "Regex" in st_enabled_scanners:
|
310 |
+
st_regex_expander = st.sidebar.expander(
|
311 |
+
"Regex",
|
312 |
+
expanded=False,
|
313 |
+
)
|
314 |
+
|
315 |
+
with st_regex_expander:
|
316 |
+
st_regex_patterns = st.text_area(
|
317 |
+
"Enter patterns to ban (one per line)",
|
318 |
+
value="Bearer [A-Za-z0-9-._~+/]+",
|
319 |
+
height=200,
|
320 |
+
).split("\n")
|
321 |
+
|
322 |
+
st_regex_type = st.selectbox(
|
323 |
+
"Match type",
|
324 |
+
["good", "bad"],
|
325 |
+
index=1,
|
326 |
+
help="good: allow only good patterns, bad: ban bad patterns",
|
327 |
+
)
|
328 |
+
|
329 |
+
st_redact = st.checkbox(
|
330 |
+
"Redact", value=False, help="Replace the matched bad patterns with [REDACTED]"
|
331 |
+
)
|
332 |
+
|
333 |
+
settings["Regex"] = {
|
334 |
+
"patterns": st_regex_patterns,
|
335 |
+
"type": st_regex_type,
|
336 |
+
"redact": st_redact,
|
337 |
+
}
|
338 |
+
|
339 |
if "Secrets" in st_enabled_scanners:
|
340 |
st_sec_expander = st.sidebar.expander(
|
341 |
"Secrets",
|
|
|
426 |
entity_types=settings["entity_types"],
|
427 |
preamble=settings["preamble"],
|
428 |
use_faker=settings["use_faker"],
|
429 |
+
threshold=settings["threshold"],
|
430 |
+
recognizer=settings["recognizer"],
|
431 |
)
|
432 |
|
433 |
if scanner_name == "BanSubstrings":
|
|
|
436 |
match_type=settings["match_type"],
|
437 |
case_sensitive=settings["case_sensitive"],
|
438 |
redact=settings["redact"],
|
439 |
+
contains_all=settings["contains_all"],
|
440 |
)
|
441 |
|
442 |
if scanner_name == "BanTopics":
|
|
|
454 |
|
455 |
return Code(allowed=allowed_languages, denied=denied_languages)
|
456 |
|
457 |
+
if scanner_name == "Language":
|
458 |
+
return Language(valid_languages=settings["valid_languages"])
|
459 |
+
|
460 |
if scanner_name == "PromptInjection":
|
461 |
return PromptInjection(threshold=settings["threshold"])
|
462 |
|
463 |
if scanner_name == "PromptInjectionV2":
|
464 |
return PromptInjectionV2(threshold=settings["threshold"])
|
465 |
|
466 |
+
if scanner_name == "Regex":
|
467 |
+
match_type = settings["type"]
|
468 |
+
|
469 |
+
good_patterns = None
|
470 |
+
bad_patterns = None
|
471 |
+
if match_type == "good":
|
472 |
+
good_patterns = settings["patterns"]
|
473 |
+
elif match_type == "bad":
|
474 |
+
bad_patterns = settings["patterns"]
|
475 |
+
|
476 |
+
return Regex(
|
477 |
+
good_patterns=good_patterns, bad_patterns=bad_patterns, redact=settings["redact"]
|
478 |
+
)
|
479 |
+
|
480 |
if scanner_name == "Secrets":
|
481 |
return Secrets(redact_mode=settings["redact_mode"])
|
482 |
|
prompt_text.txt
CHANGED
@@ -2,14 +2,14 @@ Given the personal profile of Johnathan Edward Doe, please summarize the followi
|
|
2 |
|
3 |
Profile:
|
4 |
|
5 |
-
- Full Name: Johnathan Edward Doe
|
6 |
-
- Date of Birth: April 12, 1990
|
7 |
-
- Address: 123 Elm Street, Springfield, IL, 62701
|
8 |
-
- Email: [email protected]
|
9 |
-
- Phone Number: (123) 456-7890
|
10 |
- Educational Background:
|
11 |
-
- Springfield High School, Graduated in 2008
|
12 |
-
- Springfield University, B.Sc. Computer Science, Graduated in 2012
|
13 |
- Employment:
|
14 |
-
- ABC Tech Solutions, Software Engineer, 2012-2015
|
15 |
-
- XYZ Global Systems, Senior Software Developer, 2015-2021
|
|
|
2 |
|
3 |
Profile:
|
4 |
|
5 |
+
- Full Name: Johnathan Edward Doe.
|
6 |
+
- Date of Birth: April 12, 1990.
|
7 |
+
- Address: 123 Elm Street, Springfield, IL, 62701.
|
8 |
+
- Email: [email protected].
|
9 |
+
- Phone Number: (123) 456-7890.
|
10 |
- Educational Background:
|
11 |
+
- Springfield High School, Graduated in 2008;
|
12 |
+
- Springfield University, B.Sc. Computer Science, Graduated in 2012.
|
13 |
- Employment:
|
14 |
+
- ABC Tech Solutions, Software Engineer, 2012-2015;
|
15 |
+
- XYZ Global Systems, Senior Software Developer, 2015-2021.
|
requirements.txt
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
-
|
|
|
2 |
pandas==2.1.0
|
3 |
streamlit==1.26.0
|
4 |
streamlit-tags==1.2.8
|
|
|
1 |
+
https://huggingface.co/beki/en_spacy_pii_distilbert/resolve/main/en_spacy_pii_distilbert-any-py3-none-any.whl
|
2 |
+
llm-guard==0.3.0
|
3 |
pandas==2.1.0
|
4 |
streamlit==1.26.0
|
5 |
streamlit-tags==1.2.8
|