(rsp)
| 99 | |
| 100 | |
| 101 | def parse_explore_rsp(rsp): |
| 102 | try: |
| 103 | observation = re.findall(r"Observation: (.*?)$", rsp, re.MULTILINE)[0] |
| 104 | think = re.findall(r"Thought: (.*?)$", rsp, re.MULTILINE)[0] |
| 105 | act = re.findall(r"Action: (.*?)$", rsp, re.MULTILINE)[0] |
| 106 | last_act = re.findall(r"Summary: (.*?)$", rsp, re.MULTILINE)[0] |
| 107 | print_with_color("Observation:", "yellow") |
| 108 | print_with_color(observation, "magenta") |
| 109 | print_with_color("Thought:", "yellow") |
| 110 | print_with_color(think, "magenta") |
| 111 | print_with_color("Action:", "yellow") |
| 112 | print_with_color(act, "magenta") |
| 113 | print_with_color("Summary:", "yellow") |
| 114 | print_with_color(last_act, "magenta") |
| 115 | if "FINISH" in act: |
| 116 | return ["FINISH"] |
| 117 | act_name = act.split("(")[0] |
| 118 | if act_name == "tap": |
| 119 | area = int(re.findall(r"tap\((.*?)\)", act)[0]) |
| 120 | return [act_name, area, last_act] |
| 121 | elif act_name == "text": |
| 122 | input_str = re.findall(r"text\((.*?)\)", act)[0][1:-1] |
| 123 | return [act_name, input_str, last_act] |
| 124 | elif act_name == "long_press": |
| 125 | area = int(re.findall(r"long_press\((.*?)\)", act)[0]) |
| 126 | return [act_name, area, last_act] |
| 127 | elif act_name == "swipe": |
| 128 | params = re.findall(r"swipe\((.*?)\)", act)[0] |
| 129 | area, swipe_dir, dist = params.split(",") |
| 130 | area = int(area) |
| 131 | swipe_dir = swipe_dir.strip()[1:-1] |
| 132 | dist = dist.strip()[1:-1] |
| 133 | return [act_name, area, swipe_dir, dist, last_act] |
| 134 | elif act_name == "grid": |
| 135 | return [act_name] |
| 136 | else: |
| 137 | print_with_color(f"ERROR: Undefined act {act_name}!", "red") |
| 138 | return ["ERROR"] |
| 139 | except Exception as e: |
| 140 | print_with_color(f"ERROR: an exception occurs while parsing the model response: {e}", "red") |
| 141 | print_with_color(rsp, "red") |
| 142 | return ["ERROR"] |
| 143 | |
| 144 | |
| 145 | def parse_grid_rsp(rsp): |
no test coverage detected