MCPcopy Create free account
hub / github.com/THUDM/AgentTuning / action2create_function

Function action2create_function

eval_heldout/webarena/browser_env/actions.py:164–238  ·  view source on GitHub ↗
(action: Action)

Source from the content-addressed store, hash-verified

162
163
164def action2create_function(action: Action) -> str:
165 match (action["action_type"]):
166 case ActionTypes.NONE:
167 return "create_none_action()"
168 # mouse wheel and keyboard action
169 case ActionTypes.SCROLL:
170 direction = "up" if "up" in action["direction"] else "down"
171 return f"create_scroll_action({repr(direction)})"
172 case ActionTypes.KEY_PRESS:
173 return f"create_key_press_action({repr(action['key_comb'])})"
174 # inter-page actions
175 case ActionTypes.PAGE_FOCUS:
176 return f"create_page_focus_action({action['page_number']})"
177 case ActionTypes.NEW_TAB:
178 return "create_new_tab_action()"
179 case ActionTypes.GO_BACK:
180 return "create_go_back_action()"
181 case ActionTypes.GO_FORWARD:
182 return "create_go_forward_action()"
183 case ActionTypes.GOTO_URL:
184 return f"create_goto_url_action({repr(action['url'])})"
185 case ActionTypes.PAGE_CLOSE:
186 return "create_page_close_action()"
187
188 # low-level keyboard and mouse actions
189 case ActionTypes.MOUSE_CLICK:
190 return f"create_mouse_click_action({action['coords'][0]}, {action['coords'][1]})"
191 case ActionTypes.MOUSE_HOVER:
192 return f"create_mouse_hover_action({action['coords'][0]}, {action['coords'][1]})"
193 case ActionTypes.KEYBOARD_TYPE:
194 return f"create_keyboard_type_action({list(map(lambda x: _id2key[x], action['text']))})"
195
196 # mid-level keyboard and mouse actions
197 case ActionTypes.CLICK:
198 args = []
199 args.append(f"element_id={repr(action['element_id'])}")
200 args.append(
201 f"element_role={repr(_id2role[action['element_role']])}"
202 )
203 args.append(f"element_name={repr(action['element_name'])}")
204 args.append(f"pw_code={repr(action['pw_code'])}")
205 args_str = ", ".join(args)
206 return f"create_click_action({args_str})"
207 case ActionTypes.HOVER:
208 args = []
209 args.append(f"element_id={repr(action['element_id'])}")
210 args.append(
211 f"element_role={repr(_id2role[action['element_role']])}"
212 )
213 args.append(f"element_name={repr(action['element_name'])}")
214 args.append(f"pw_code={repr(action['pw_code'])}")
215 args_str = ", ".join(args)
216 return f"create_hover_action({args_str})"
217 case ActionTypes.TYPE:
218 args = []
219 text = "".join(map(lambda x: _id2key[x], action["text"]))
220 args.append(f"text={repr(text)}")
221 args.append(f"element_id={repr(action['element_id'])}")

Callers

nothing calls this directly

Calls 1

joinMethod · 0.80

Tested by

no test coverage detected