MCPcopy Create free account
hub / github.com/OpenBMB/AgentCPM-GUI / build_data_episodes

Function build_data_episodes

eval/run_predict_odyssey.py:330–409  ·  view source on GitHub ↗

Transfrom the episode trajectory into Odyssey data. This function work as the data preprocess of the origin repo. Args: episode_dir (str): the directory of the episodes. episodes_files (List[str]): the files in the episodes directory. dataset_name (str): the na

(episode_dir:str,
                        episodes_files:List[str],
                        dataset_name:str,
                        his_len:int = 4)

Source from the content-addressed store, hash-verified

328 raise NotImplementedError
329
330def build_data_episodes(episode_dir:str,
331 episodes_files:List[str],
332 dataset_name:str,
333 his_len:int = 4) -> List[Dict]:
334 """
335 Transfrom the episode trajectory into Odyssey data.
336
337 This function work as the data preprocess of the origin repo.
338
339 Args:
340 episode_dir (str): the directory of the episodes.
341 episodes_files (List[str]): the files in the episodes directory.
342 dataset_name (str): the name of the dataset.
343 his_len (int, optional): the max length of history included. Defaults to 4.
344
345 Returns:
346 List[Dict]: a series of data that would be processed later.
347 """
348
349 res:list = []
350
351 for episodes_file in episodes_files:
352 episodes_path = os.path.join(episode_dir, episodes_file, f"{episodes_file}.json")
353 try:
354 with open(episodes_path, 'r', encoding='utf-8') as f:
355 episodes = json.load(f)
356 except Exception as e:
357 print(f"Failed to load {episodes_path}: {e}")
358 continue
359 # Skip this file on error
360
361 history_action:list = []
362 history_screenshot:list = []
363
364 for episode in episodes:
365
366 image_path = os.path.join(episode_dir, episodes_file, f"{episodes_file}_{episode['step_id']}.jpeg")
367 if not os.path.exists(image_path):
368 image_path = image_path.replace(".jpeg", ".png")
369 if not os.path.exists(image_path):
370 image_path = episode['image_path']
371
372 gt = transform_actions(episode)
373
374 if dataset_name == 'android_control_high_test':
375 instruction = episode["low_instruction"]
376 else:
377 instruction = episode["instruction"]
378
379 question = f"Picture 1: <img>{image_path}</img>\nI'm looking for guidance on how to {instruction}"
380
381 history_action = history_action[-his_len :]
382
383 if IMAGE_HISTORY:
384 if len(history_action) > 0:
385 his_img = f'\nPrevious screenshots: <img>image-history: {image_path}</img>'
386 his_str = '\nPrevious Actions: '
387 for idx, hi in enumerate(history_action):

Callers 1

predictFunction · 0.85

Calls 1

transform_actionsFunction · 0.85

Tested by

no test coverage detected