asofter commited on
Commit
10cef3f
1 Parent(s): 61173ea

* upgrade version

Browse files

* add Gibberish scanner

Files changed (3) hide show
  1. output.py +26 -4
  2. prompt.py +38 -1
  3. requirements.txt +4 -4
output.py CHANGED
@@ -9,8 +9,8 @@ from llm_guard.input_scanners.code import SUPPORTED_LANGUAGES as SUPPORTED_CODE_
9
  from llm_guard.output_scanners import get_scanner_by_name
10
  from llm_guard.output_scanners.bias import MatchType as BiasMatchType
11
  from llm_guard.output_scanners.deanonymize import MatchingStrategy as DeanonymizeMatchingStrategy
 
12
  from llm_guard.output_scanners.language import MatchType as LanguageMatchType
13
- from llm_guard.output_scanners.relevance import all_models as relevance_models
14
  from llm_guard.output_scanners.toxicity import MatchType as ToxicityMatchType
15
  from llm_guard.vault import Vault
16
  from streamlit_tags import st_tags
@@ -33,6 +33,7 @@ def init_settings() -> (List, Dict):
33
  "NoRefusal",
34
  "ReadingTime",
35
  "FactualConsistency",
 
36
  "Regex",
37
  "Relevance",
38
  "Sensitive",
@@ -389,9 +390,7 @@ def init_settings() -> (List, Dict):
389
  key="rele_threshold",
390
  )
391
 
392
- st_rele_model = st.selectbox("Embeddings model", relevance_models, index=1)
393
-
394
- settings["Relevance"] = {"threshold": st_rele_threshold, "model": st_rele_model}
395
 
396
  if "Sensitive" in st_enabled_scanners:
397
  st_sens_expander = st.sidebar.expander(
@@ -484,6 +483,28 @@ def init_settings() -> (List, Dict):
484
  if st_url_expander:
485
  settings["URLReachability"] = {}
486
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
487
  return st_enabled_scanners, settings
488
 
489
 
@@ -497,6 +518,7 @@ def get_scanner(scanner_name: str, vault: Vault, settings: Dict):
497
  "BanTopics",
498
  "Bias",
499
  "Code",
 
500
  "Language",
501
  "LanguageSame",
502
  "MaliciousURLs",
 
9
  from llm_guard.output_scanners import get_scanner_by_name
10
  from llm_guard.output_scanners.bias import MatchType as BiasMatchType
11
  from llm_guard.output_scanners.deanonymize import MatchingStrategy as DeanonymizeMatchingStrategy
12
+ from llm_guard.output_scanners.gibberish import MatchType as GibberishMatchType
13
  from llm_guard.output_scanners.language import MatchType as LanguageMatchType
 
14
  from llm_guard.output_scanners.toxicity import MatchType as ToxicityMatchType
15
  from llm_guard.vault import Vault
16
  from streamlit_tags import st_tags
 
33
  "NoRefusal",
34
  "ReadingTime",
35
  "FactualConsistency",
36
+ "Gibberish",
37
  "Regex",
38
  "Relevance",
39
  "Sensitive",
 
390
  key="rele_threshold",
391
  )
392
 
393
+ settings["Relevance"] = {"threshold": st_rele_threshold}
 
 
394
 
395
  if "Sensitive" in st_enabled_scanners:
396
  st_sens_expander = st.sidebar.expander(
 
483
  if st_url_expander:
484
  settings["URLReachability"] = {}
485
 
486
+ if "Gibberish" in st_enabled_scanners:
487
+ st_gib_expander = st.sidebar.expander(
488
+ "Gibberish",
489
+ expanded=False,
490
+ )
491
+
492
+ with st_gib_expander:
493
+ st_gib_threshold = st.slider(
494
+ label="Threshold",
495
+ value=0.7,
496
+ min_value=0.0,
497
+ max_value=1.0,
498
+ step=0.1,
499
+ key="gib_threshold",
500
+ )
501
+
502
+ st_gib_match_type = st.selectbox(
503
+ "Match type", [e.value for e in GibberishMatchType], index=1, key="gib_match_type"
504
+ )
505
+
506
+ settings["Gibberish"] = {"match_type": st_gib_match_type, "threshold": st_gib_threshold}
507
+
508
  return st_enabled_scanners, settings
509
 
510
 
 
518
  "BanTopics",
519
  "Bias",
520
  "Code",
521
+ "Gibberish",
522
  "Language",
523
  "LanguageSame",
524
  "MaliciousURLs",
prompt.py CHANGED
@@ -7,6 +7,7 @@ import streamlit as st
7
  from llm_guard.input_scanners import get_scanner_by_name
8
  from llm_guard.input_scanners.anonymize import default_entity_types
9
  from llm_guard.input_scanners.code import SUPPORTED_LANGUAGES as SUPPORTED_CODE_LANGUAGES
 
10
  from llm_guard.input_scanners.language import MatchType as LanguageMatchType
11
  from llm_guard.input_scanners.prompt_injection import MatchType as PromptInjectionMatchType
12
  from llm_guard.input_scanners.toxicity import MatchType as ToxicityMatchType
@@ -23,6 +24,7 @@ def init_settings() -> (List, Dict):
23
  "BanSubstrings",
24
  "BanTopics",
25
  "Code",
 
26
  "Language",
27
  "PromptInjection",
28
  "Regex",
@@ -215,6 +217,34 @@ def init_settings() -> (List, Dict):
215
  "is_blocked": st_cd_is_blocked,
216
  }
217
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  if "Language" in st_enabled_scanners:
219
  st_lan_expander = st.sidebar.expander(
220
  "Language",
@@ -410,7 +440,14 @@ def get_scanner(scanner_name: str, vault: Vault, settings: Dict):
410
  if scanner_name == "Anonymize":
411
  settings["vault"] = vault
412
 
413
- if scanner_name in ["Anonymize", "BanTopics", "Code", "PromptInjection", "Toxicity"]:
 
 
 
 
 
 
 
414
  settings["use_onnx"] = True
415
 
416
  return get_scanner_by_name(scanner_name, settings)
 
7
  from llm_guard.input_scanners import get_scanner_by_name
8
  from llm_guard.input_scanners.anonymize import default_entity_types
9
  from llm_guard.input_scanners.code import SUPPORTED_LANGUAGES as SUPPORTED_CODE_LANGUAGES
10
+ from llm_guard.input_scanners.gibberish import MatchType as GibberishMatchType
11
  from llm_guard.input_scanners.language import MatchType as LanguageMatchType
12
  from llm_guard.input_scanners.prompt_injection import MatchType as PromptInjectionMatchType
13
  from llm_guard.input_scanners.toxicity import MatchType as ToxicityMatchType
 
24
  "BanSubstrings",
25
  "BanTopics",
26
  "Code",
27
+ "Gibberish",
28
  "Language",
29
  "PromptInjection",
30
  "Regex",
 
217
  "is_blocked": st_cd_is_blocked,
218
  }
219
 
220
+ if "Gibberish" in st_enabled_scanners:
221
+ st_gib_expander = st.sidebar.expander(
222
+ "Gibberish",
223
+ expanded=False,
224
+ )
225
+
226
+ with st_gib_expander:
227
+ st_gib_threshold = st.slider(
228
+ label="Threshold",
229
+ value=0.7,
230
+ min_value=0.0,
231
+ max_value=1.0,
232
+ step=0.1,
233
+ key="gibberish_threshold",
234
+ )
235
+
236
+ st_gib_match_type = st.selectbox(
237
+ "Match type",
238
+ [e.value for e in GibberishMatchType],
239
+ index=1,
240
+ key="gibberish_match_type",
241
+ )
242
+
243
+ settings["Gibberish"] = {
244
+ "threshold": st_gib_threshold,
245
+ "match_type": st_gib_match_type,
246
+ }
247
+
248
  if "Language" in st_enabled_scanners:
249
  st_lan_expander = st.sidebar.expander(
250
  "Language",
 
440
  if scanner_name == "Anonymize":
441
  settings["vault"] = vault
442
 
443
+ if scanner_name in [
444
+ "Anonymize",
445
+ "BanTopics",
446
+ "Code",
447
+ "Gibberish",
448
+ "PromptInjection",
449
+ "Toxicity",
450
+ ]:
451
  settings["use_onnx"] = True
452
 
453
  return get_scanner_by_name(scanner_name, settings)
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
- llm-guard==0.3.9
2
- llm-guard[onnxruntime]==0.3.9
3
- pandas==2.2.0
4
- streamlit==1.31.0
5
  streamlit-tags==1.2.8
 
1
+ llm-guard==0.3.10
2
+ llm-guard[onnxruntime]==0.3.10
3
+ pandas==2.2.1
4
+ streamlit==1.32.1
5
  streamlit-tags==1.2.8