(rsp)
| 143 | |
| 144 | |
| 145 | def parse_grid_rsp(rsp): |
| 146 | try: |
| 147 | observation = re.findall(r"Observation: (.*?)$", rsp, re.MULTILINE)[0] |
| 148 | think = re.findall(r"Thought: (.*?)$", rsp, re.MULTILINE)[0] |
| 149 | act = re.findall(r"Action: (.*?)$", rsp, re.MULTILINE)[0] |
| 150 | last_act = re.findall(r"Summary: (.*?)$", rsp, re.MULTILINE)[0] |
| 151 | print_with_color("Observation:", "yellow") |
| 152 | print_with_color(observation, "magenta") |
| 153 | print_with_color("Thought:", "yellow") |
| 154 | print_with_color(think, "magenta") |
| 155 | print_with_color("Action:", "yellow") |
| 156 | print_with_color(act, "magenta") |
| 157 | print_with_color("Summary:", "yellow") |
| 158 | print_with_color(last_act, "magenta") |
| 159 | if "FINISH" in act: |
| 160 | return ["FINISH"] |
| 161 | act_name = act.split("(")[0] |
| 162 | if act_name == "tap": |
| 163 | params = re.findall(r"tap\((.*?)\)", act)[0].split(",") |
| 164 | area = int(params[0].strip()) |
| 165 | subarea = params[1].strip()[1:-1] |
| 166 | return [act_name + "_grid", area, subarea, last_act] |
| 167 | elif act_name == "long_press": |
| 168 | params = re.findall(r"long_press\((.*?)\)", act)[0].split(",") |
| 169 | area = int(params[0].strip()) |
| 170 | subarea = params[1].strip()[1:-1] |
| 171 | return [act_name + "_grid", area, subarea, last_act] |
| 172 | elif act_name == "swipe": |
| 173 | params = re.findall(r"swipe\((.*?)\)", act)[0].split(",") |
| 174 | start_area = int(params[0].strip()) |
| 175 | start_subarea = params[1].strip()[1:-1] |
| 176 | end_area = int(params[2].strip()) |
| 177 | end_subarea = params[3].strip()[1:-1] |
| 178 | return [act_name + "_grid", start_area, start_subarea, end_area, end_subarea, last_act] |
| 179 | elif act_name == "grid": |
| 180 | return [act_name] |
| 181 | else: |
| 182 | print_with_color(f"ERROR: Undefined act {act_name}!", "red") |
| 183 | return ["ERROR"] |
| 184 | except Exception as e: |
| 185 | print_with_color(f"ERROR: an exception occurs while parsing the model response: {e}", "red") |
| 186 | print_with_color(rsp, "red") |
| 187 | return ["ERROR"] |
| 188 | |
| 189 | |
| 190 | def parse_reflect_rsp(rsp): |
no test coverage detected