MCPcopy Create free account
hub / github.com/ChenWu98/agent-attack / eval_from_file

Function eval_from_file

scripts/eval_step.py:261–280  ·  view source on GitHub ↗
(args: argparse.Namespace, dataset, use_caption=True)

Source from the content-addressed store, hash-verified

259
260@beartype
261def eval_from_file(args: argparse.Namespace, dataset, use_caption=True) -> None:
262 result_path = Path(args.result_dir) / f"actions_{'caption' if use_caption else 'no_caption'}.json"
263 with open(result_path, "r") as f:
264 all_actions = json.load(f)
265 all_labels = {}
266 for example in dataset:
267 all_labels[example["id"]] = example["label"]
268
269 evaluator = StepEvaluator()
270
271 correct = {}
272 for example_id, action in all_actions.items():
273 label = all_labels[example_id]
274 correct[example_id] = evaluator(action, label)
275
276 print(f"Benign success rate: {sum(correct.values())}/{len(all_actions)}")
277
278 # write to file
279 with open(Path(args.result_dir) / f"correct_{'caption' if use_caption else 'no_caption'}.json", "w") as f:
280 json.dump(correct, f, indent=4)
281
282
283def prepare(args: argparse.Namespace) -> None:

Callers 1

eval_step.pyFile · 0.70

Calls 2

StepEvaluatorClass · 0.90
loadMethod · 0.45

Tested by

no test coverage detected