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

Function process_step_data

eval/run_eval_agent.py:94–138  ·  view source on GitHub ↗

Process a single step of data, load prediction results and evaluate. Args: step_data (dict): Data of a single step. Returns: dict or None: None means the step hasn't been predicted yet. Empty JSON indicates JSON parsing failed.

(step_data, evaluator, save_dir)

Source from the content-addressed store, hash-verified

92 return self.data[index]
93
94def process_step_data(step_data, evaluator, save_dir):
95 """
96 Process a single step of data, load prediction results and evaluate.
97
98 Args:
99 step_data (dict): Data of a single step.
100
101 Returns:
102 dict or None: None means the step hasn't been predicted yet. Empty JSON indicates JSON parsing failed.
103 """
104
105 subset = step_data.get('subset')
106 episode_id = step_data.get('episode_id')
107 step_id = step_data.get('step_id')
108
109 if subset is None or episode_id is None or step_id is None:
110 raise ValueError(f"Missing subset/episode_id/step_id in test step data: {step_data}")
111
112 save_dir_ep = os.path.join(save_dir, f"{subset}-{episode_id}")
113 cur_save_path = os.path.join(save_dir_ep, f"{subset}-{episode_id}_{step_id}.json")
114
115 try:
116 # Ensure directory exists
117 os.makedirs(os.path.dirname(cur_save_path), exist_ok=True)
118
119 # Check if the file exists; if not, the step hasn't been predicted yet
120 if not os.path.exists(cur_save_path):
121 return None
122
123 # Load the existing file
124 with open(cur_save_path, "r") as file:
125 try:
126 pred = json.load(file)
127 except json.JSONDecodeError as e:
128 logging.error(f"JSON decoding failed, file: {cur_save_path}, error: {e}")
129 pred = {'action_predict': {'COA': {'txt': {'ACTION': None, 'ARGS': None, 'STATUS': None}}}}
130
131 assert pred is not None
132
133 # Use global evaluator to evaluate
134 result = evaluator(step_data, pred)
135 return result
136
137 except Exception as e:
138 raise ExecError(f"An error occurred, indicating unhandled edge case.")
139
140def evaluate(args):
141

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected