MCPcopy Create free account
hub / github.com/THUDM/AutoWebGLM / action2str

Function action2str

webarena/browser_env/actions.py:112–247  ·  view source on GitHub ↗

Return the string representation of an action sementic_element: the semantic information of the element such as a line in an accessibility tree

(
    action: Action, action_set_tag: str, semantic_element: str = ""
)

Source from the content-addressed store, hash-verified

110
111@beartype
112def action2str(
113 action: Action, action_set_tag: str, semantic_element: str = ""
114) -> str:
115 """Return the string representation of an action
116
117 sementic_element: the semantic information of the element
118 such as a line in an accessibility tree
119 """
120 if action_set_tag == "id_accessibility_tree":
121 element_id = action["element_id"]
122 match action["action_type"]:
123 case ActionTypes.CLICK:
124 # [ID=X] xxxxx
125 action_str = f"click [{element_id}] where [{element_id}] is {semantic_element}"
126 case ActionTypes.TYPE:
127 text = "".join([_id2key[i] for i in action["text"]])
128 text = text.replace("\n", " ")
129 action_str = f"type [{element_id}] [{text}] where [{element_id}] is {semantic_element}"
130 case ActionTypes.HOVER:
131 action_str = f"hover [{element_id}] where [{element_id}] is {semantic_element}"
132 case ActionTypes.SCROLL:
133 action_str = f"scroll [{action['direction']}]"
134 case ActionTypes.KEY_PRESS:
135 action_str = f"press [{action['key_comb']}]"
136 case ActionTypes.GOTO_URL:
137 action_str = f"goto [{action['url']}]"
138 case ActionTypes.NEW_TAB:
139 action_str = "new_tab"
140 case ActionTypes.PAGE_CLOSE:
141 action_str = "close_tab"
142 case ActionTypes.GO_BACK:
143 action_str = "go_back"
144 case ActionTypes.GO_FORWARD:
145 action_str = "go_forward"
146 case ActionTypes.PAGE_FOCUS:
147 action_str = f"page_focus [{action['page_number']}]"
148 case ActionTypes.STOP:
149 action_str = f"stop [{action['answer']}]"
150 case ActionTypes.NONE:
151 action_str = "none"
152 case _:
153 raise ValueError(
154 f"Unknown action type {action['action_type']}"
155 )
156 elif action_set_tag == "id_html_tree":
157 element_id = action["element_id"]
158 label = action.get("label", "")
159 match action["action_type"]:
160 case ActionTypes.CLICK:
161 # [ID=X] xxxxx
162 action_str = f"#Click# {label}"
163 case ActionTypes.TYPE:
164 text = "".join([_id2key[i] for i in action["text"]])
165 text = text.replace("\n", " ")
166 action_str = f"#Type# {label} {text}"
167 case ActionTypes.HOVER:
168 action_str = f"#Hover# {label}"
169 case ActionTypes.SCROLL:

Callers 2

get_render_actionFunction · 0.90
get_action_descriptionFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected