(res:str, solution: dict, reso: tuple, bbox: list[list], step_id)
| 222 | return scores |
| 223 | |
| 224 | def _react_check(res:str, solution: dict, reso: tuple, bbox: list[list], step_id): |
| 225 | if isinstance(solution,str): |
| 226 | return difflib.SequenceMatcher(None, res,solution).ratio() |
| 227 | |
| 228 | res = res.strip() |
| 229 | if ( |
| 230 | res.count("<think>") != 1 or |
| 231 | res.count("</think>") != 1 or |
| 232 | res.count("<act>") != 1 or |
| 233 | res.count("</act>") != 1 or |
| 234 | not res.endswith("</act>") |
| 235 | ): |
| 236 | return -1.0 |
| 237 | |
| 238 | if step_id == 0: |
| 239 | if not res.startswith("<plan>") or res.count("</plan>") != 1: |
| 240 | return -1.0 |
| 241 | else: |
| 242 | if not (res.startswith("<reflection>") or res.startswith("<think>")): |
| 243 | return -1.0 |
| 244 | |
| 245 | if not ("<think>" in res and "</think>" in res) or res.startswith("<act>"): |
| 246 | return - 1.0 |
| 247 | # extract the think content |
| 248 | think_str = re.search(r'<think>(.*?)</think>', res, re.DOTALL) |
| 249 | if think_str: |
| 250 | think_str = think_str.group(1).strip() |
| 251 | else: |
| 252 | return - 1.0 |
| 253 | |
| 254 | # check the action |
| 255 | try: |
| 256 | act_str = re.search(r'<act>(.*?)</act>', res, re.DOTALL).group(1).strip() |
| 257 | action = load_and_validate_action(act_str) |
| 258 | except: |
| 259 | return - 1.0 |
| 260 | |
| 261 | action_keys = set(action.keys()) |
| 262 | solution_keys = set(solution.keys()) |
| 263 | |
| 264 | if action_keys != solution_keys: |
| 265 | return len(action_keys & solution_keys) / len(solution_keys.union(action_keys)) - 1 |
| 266 | |
| 267 | score = 0.0 |
| 268 | |
| 269 | sub_scores = [] |
| 270 | for k in solution.keys(): |
| 271 | if k not in action: |
| 272 | sub_scores.append(0) |
| 273 | continue |
| 274 | sub_score = 0 |
| 275 | match k: |
| 276 | case "POINT": |
| 277 | sub_score += calculate_dist_score(action[k], solution[k], reso, bbox[0]) |
| 278 | |
| 279 | case "duration": |
| 280 | if action[k] > 150 and action[k] <= 5000: |
| 281 | sub_score += 1.0 |
nothing calls this directly
no test coverage detected