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

Function transform_actions

eval/run_predict_odyssey.py:155–200  ·  view source on GitHub ↗

Transform the action space from minicpm towards Odyssey. Args: action: the origin action space. Returns: str: the same action described in odyssey dataset.

(action:dict)

Source from the content-addressed store, hash-verified

153
154
155def transform_actions(action:dict) -> str:
156 """
157 Transform the action space from minicpm towards Odyssey.
158
159 Args:
160 action: the origin action space.
161
162 Returns:
163 str: the same action described in odyssey dataset.
164 """
165 action_type:int = action["result_action_type"]
166
167 if action_type == 7:
168 return 'PRESS_ENTER' # Not in Odyssey's action space.
169 elif action_type == 1:
170 return 'NO_ACTION' # Not in Odyssey's action space.
171 elif action_type == 3:
172 return f'TYPE: {action["result_action_text"]}'
173 elif action_type == 6:
174 return 'PRESS_HOME'
175 elif action_type == 5:
176 return 'PRESS_BACK'
177 elif action_type == 7:
178 return 'PRESS_ENTER'
179 elif action_type == 10:
180 return 'COMPLETE'
181 elif action_type == 11:
182 return 'IMPOSSIBLE'
183 elif action_type == 0:
184 # Deal with the long press.
185 y, x = map(lambda x: round(x * 1000), json.loads(action["result_touch_yx"]))
186 return f'LONG_PRESS ({x}, {y})'
187
188 elif action_type == 4:
189 # deal with the click or scroll.
190 sy, sx = map(lambda x: round(x * 1000), json.loads(action["result_touch_yx"]))
191 ey, ex = map(lambda x: round(x * 1000), json.loads(action["result_lift_yx"]))
192
193 if sx == ex and sy == ey:
194 return f'CLICK: ({ex}, {ey})'
195 else:
196 direction = get_direction({"x":sx, "y":sy}, {"x": ex, "y": ey})
197 return f'SCROLL: {direction.upper()}'
198
199 else:
200 raise NotImplementedError (f"No matching type for type {action_type}")
201
202
203def make_his_idx(episode_dir:str,

Callers 1

build_data_episodesFunction · 0.85

Calls 1

get_directionFunction · 0.70

Tested by

no test coverage detected