Mapping the string from aguvis model into minicpm Action space. Args: episode (dict): The episode dict, containing all information and a prediction string. Returns: the episode whose prediction string is mapped into minicpm Action space. In practice the model will
(episode: dict)
| 216 | |
| 217 | # action mapping begins. =========== |
| 218 | def mapping_actions(episode: dict) -> dict: |
| 219 | """ |
| 220 | Mapping the string from aguvis model into minicpm Action space. |
| 221 | |
| 222 | Args: |
| 223 | episode (dict): The episode dict, containing all information and a prediction string. |
| 224 | |
| 225 | Returns: |
| 226 | the episode whose prediction string is mapped into minicpm Action space. |
| 227 | |
| 228 | In practice the model will output unstable strings. We only handle those stable cases. |
| 229 | """ |
| 230 | |
| 231 | FAIL_PARSE = { |
| 232 | "STATUS": "FAIL" |
| 233 | } |
| 234 | |
| 235 | action:str = episode["pred"].split('\n')[-1].strip() |
| 236 | |
| 237 | platform = action.split('.')[0] |
| 238 | |
| 239 | function = action[len(platform) + 1 :] |
| 240 | |
| 241 | if platform == "pyautogui": |
| 242 | |
| 243 | if function.startswith("click"): |
| 244 | # deal with click function. |
| 245 | try: |
| 246 | matches = re.findall(r"[-+]?\d*\.\d+|\d+", function) |
| 247 | x,y = matches |
| 248 | x = round(float(x) * 1000) |
| 249 | y = round(float(y) * 1000) |
| 250 | |
| 251 | episode["pred"] = { |
| 252 | "POINT": [x, y], |
| 253 | "duration": 200, |
| 254 | "STATUS": "continue" |
| 255 | } |
| 256 | except Exception as e: |
| 257 | print(f"Failed to parse POINT ACTION {function}: {e}") |
| 258 | episode["pred"] = FAIL_PARSE |
| 259 | |
| 260 | elif function.startswith("write"): |
| 261 | # deal with type action. |
| 262 | try: |
| 263 | |
| 264 | pattern = r'message=(["\'])(.*?)\1' |
| 265 | match = re.search(pattern, function) |
| 266 | |
| 267 | text = match.group(2) |
| 268 | |
| 269 | episode["pred"] = { |
| 270 | "TYPE": text, |
| 271 | "duration": 200, |
| 272 | "STATUS": "continue" |
| 273 | } |
| 274 | |
| 275 | except Exception as e: |