Parse a string like "content=[{'type': 'text', 'text': '4.2426'}]".
(self, repr_str: str)
| 1363 | return self._try_parse_number(combined) |
| 1364 | |
| 1365 | def _parse_content_repr(self, repr_str: str) -> Any: |
| 1366 | """Parse a string like "content=[{'type': 'text', 'text': '4.2426'}]".""" |
| 1367 | import re |
| 1368 | |
| 1369 | # Try to extract the text value using regex |
| 1370 | match = re.search(r"'text':\s*'([^']*)'", repr_str) |
| 1371 | if match: |
| 1372 | text = match.group(1) |
| 1373 | return self._try_parse_number(text) |
| 1374 | |
| 1375 | # Try another pattern for double quotes |
| 1376 | match = re.search(r'"text":\s*"([^"]*)"', repr_str) |
| 1377 | if match: |
| 1378 | text = match.group(1) |
| 1379 | return self._try_parse_number(text) |
| 1380 | |
| 1381 | return repr_str |
| 1382 | |
| 1383 | def _try_parse_number(self, text: str) -> Any: |
| 1384 | """Try to parse a string as a number, return original if not possible.""" |