Parse the predicted actions for rendering purpose. More comprehensive information
(
action: Action,
observation_metadata: dict[str, ObservationMetadata],
action_set_tag: str,
)
| 35 | |
| 36 | |
| 37 | def get_render_action( |
| 38 | action: Action, |
| 39 | observation_metadata: dict[str, ObservationMetadata], |
| 40 | action_set_tag: str, |
| 41 | ) -> str: |
| 42 | """Parse the predicted actions for rendering purpose. More comprehensive information""" |
| 43 | match action_set_tag: |
| 44 | case "id_html_tree": |
| 45 | text_meta_data = observation_metadata["text"] |
| 46 | if action["element_id"] in text_meta_data["obs_nodes_info"]: |
| 47 | node_content = text_meta_data["obs_nodes_info"][ |
| 48 | action["element_id"] |
| 49 | ]["text"] |
| 50 | else: |
| 51 | node_content = "No match found" |
| 52 | |
| 53 | action_str = f"<div class='raw_parsed_prediction' style='background-color:grey'><pre>{action['raw_prediction']}</pre></div>" |
| 54 | action_str += f"<div class='action_object' style='background-color:grey'><pre>{repr(action)}</pre></div>" |
| 55 | action_str += f"<div class='parsed_action' style='background-color:yellow'><pre>{action2str(action, action_set_tag, node_content)}</pre></div>" |
| 56 | |
| 57 | case "id_html_nasc_tree": |
| 58 | text_meta_data = observation_metadata["text"] |
| 59 | if action["element_id"] in text_meta_data["obs_nodes_info"]: |
| 60 | node_content = text_meta_data["obs_nodes_info"][ |
| 61 | action["element_id"] |
| 62 | ]["text"] |
| 63 | else: |
| 64 | node_content = "No match found" |
| 65 | |
| 66 | action_str = f"<div class='raw_parsed_prediction' style='background-color:grey'><pre>{action['raw_prediction']}</pre></div>" |
| 67 | action_str += f"<div class='action_object' style='background-color:grey'><pre>{repr(action)}</pre></div>" |
| 68 | action_str += f"<div class='parsed_action' style='background-color:yellow'><pre>{action2str(action, action_set_tag, node_content)}</pre></div>" |
| 69 | |
| 70 | case "id_accessibility_tree": |
| 71 | text_meta_data = observation_metadata["text"] |
| 72 | if action["element_id"] in text_meta_data["obs_nodes_info"]: |
| 73 | node_content = text_meta_data["obs_nodes_info"][ |
| 74 | action["element_id"] |
| 75 | ]["text"] |
| 76 | else: |
| 77 | node_content = "No match found" |
| 78 | |
| 79 | action_str = f"<div class='raw_parsed_prediction' style='background-color:grey'><pre>{action['raw_prediction']}</pre></div>" |
| 80 | action_str += f"<div class='action_object' style='background-color:grey'><pre>{repr(action)}</pre></div>" |
| 81 | action_str += f"<div class='parsed_action' style='background-color:yellow'><pre>{action2str(action, action_set_tag, node_content)}</pre></div>" |
| 82 | |
| 83 | case "playwright": |
| 84 | action_str = action["pw_code"] |
| 85 | case _: |
| 86 | raise ValueError(f"Unknown action type {action['action_type']}") |
| 87 | return action_str |
| 88 | |
| 89 | |
| 90 | def get_action_description( |