Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle extant but closed hitlogfile file #665

Merged
merged 1 commit into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions garak/evaluators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ def evaluate(self, attempts: List[garak.attempt.Attempt]) -> None:
all_outputs += attempt.outputs
for idx, score in enumerate(attempt.detector_results[detector]):
if not self.test(score): # if we don't pass
if not _config.transient.hitlogfile:
if (
_config.transient.hitlogfile is None
or _config.transient.hitlogfile.closed
):
hitlog_mode = (
"w" if _config.transient.hitlogfile is None else "a"
)
if not _config.reporting.report_prefix:
hitlog_filename = f"{_config.reporting.report_dir}/garak.{_config.transient.run_id}.hitlog.jsonl"
else:
Expand All @@ -72,7 +78,7 @@ def evaluate(self, attempts: List[garak.attempt.Attempt]) -> None:
logging.info("hit log in %s", hitlog_filename)
_config.transient.hitlogfile = open(
hitlog_filename,
"w",
hitlog_mode,
buffering=1,
encoding="utf-8",
)
Expand Down
Loading