From 9df0d8e2c3c3f4fbb23955c1121f37271d051b8d Mon Sep 17 00:00:00 2001 From: Leon Derczynski Date: Tue, 30 Jul 2024 18:53:51 +0200 Subject: [PATCH] don't skip listing probes in 100%-pass-rate modules (#781) * don't skip listing probes in 100%-pass-rate modules * add config option for hiding/showing reports of modules where score is 100% * ensure encoding for stdout on launchable scripts Signed-off-by: Jeffrey Martin --------- Signed-off-by: Jeffrey Martin Co-authored-by: Jeffrey Martin --- garak/__main__.py | 1 + garak/analyze/report_digest.py | 8 ++++++-- garak/interactive.py | 1 + garak/resources/garak.core.yaml | 3 ++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/garak/__main__.py b/garak/__main__.py index 7603c4e4c..923bbebdc 100644 --- a/garak/__main__.py +++ b/garak/__main__.py @@ -10,4 +10,5 @@ def main(): if __name__ == "__main__": + sys.stdout.reconfigure(encoding="utf-8") main() diff --git a/garak/analyze/report_digest.py b/garak/analyze/report_digest.py index 838111413..b446d5114 100644 --- a/garak/analyze/report_digest.py +++ b/garak/analyze/report_digest.py @@ -15,6 +15,9 @@ from garak import _config +if not _config.loaded: + _config.load_config() + templateLoader = jinja2.FileSystemLoader( searchpath=_config.transient.package_dir / "analyze" / "templates" ) @@ -174,7 +177,7 @@ def compile_digest(report_path, taxonomy=_config.reporting.taxonomy): } ) - if top_score < 100.0: + if top_score < 100.0 or _config.reporting.show_100_pass_modules: res = cursor.execute( f"select probe_module, probe_class, avg(score)*100 as s from results where probe_group='{probe_group}' group by probe_class order by s asc, probe_class asc;" ) @@ -226,9 +229,10 @@ def compile_digest(report_path, taxonomy=_config.reporting.taxonomy): if __name__ == "__main__": + sys.stdout.reconfigure(encoding="utf-8") report_path = sys.argv[1] taxonomy = None if len(sys.argv) == 3: taxonomy = sys.argv[2] digest_content = compile_digest(report_path, taxonomy=taxonomy) - print(digest_content.encode("utf-8")) + print(digest_content) diff --git a/garak/interactive.py b/garak/interactive.py index 5e9fb4baf..8005ca9f5 100644 --- a/garak/interactive.py +++ b/garak/interactive.py @@ -249,4 +249,5 @@ def interactive_mode(): if __name__ == "__main__": + sys.stdout.reconfigure(encoding="utf-8") interactive_mode() diff --git a/garak/resources/garak.core.yaml b/garak/resources/garak.core.yaml index 75670a530..02d765308 100644 --- a/garak/resources/garak.core.yaml +++ b/garak/resources/garak.core.yaml @@ -34,4 +34,5 @@ plugins: reporting: report_prefix: taxonomy: - report_dir: garak_runs \ No newline at end of file + report_dir: garak_runs + show_100_pass_modules: true \ No newline at end of file