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

Function get_examples

agent_attack/data/clean_data.py:20–56  ·  view source on GitHub ↗
(traj_root)

Source from the content-addressed store, hash-verified

18
19
20def get_examples(traj_root):
21 examples = []
22 # Enumerate all directory names in the root directory
23 for dir_name in sorted(os.listdir(traj_root)):
24 if dir_name == ".DS_Store":
25 continue
26
27 # Enumerate all files in the directory
28 example_dir = os.path.join(traj_root, dir_name)
29
30 with open(os.path.join(example_dir, "data.json")) as f:
31 data = json.load(f)
32
33 with open(os.path.join(example_dir, "obs_text.txt")) as f:
34 obs_text = f.read().strip()
35 no_cap_obs_text = remove_caption(obs_text)
36
37 obs_screenshot = Image.open(os.path.join(example_dir, "obs_screenshot.png"))
38 if os.path.exists(query_image_path := os.path.join(example_dir, "query_image.png")):
39 query_image = Image.open(query_image_path)
40 else:
41 query_image = None
42
43 example = {
44 "id": dir_name,
45 "intent": data["intent"],
46 "query_image": query_image,
47 "obs_text": obs_text,
48 "no_cap_obs_text": no_cap_obs_text,
49 "obs_screenshot": obs_screenshot,
50 "obs_url": data["obs_url"],
51 "previous_action": data["previous_action"],
52 "label": data["label"],
53 }
54 examples.append(example)
55
56 return examples

Callers 1

eval_step.pyFile · 0.90

Calls 2

remove_captionFunction · 0.70
loadMethod · 0.45

Tested by

no test coverage detected