Attempt to extract the first JSON object string from plain text.
(text: str)
| 5 | |
| 6 | |
| 7 | def extract_json_from_text(text: str) -> Optional[str]: |
| 8 | """Attempt to extract the first JSON object string from plain text.""" |
| 9 | if not text: |
| 10 | return None |
| 11 | # Simple heuristic: find the first '{' and the last matching '}' |
| 12 | try: |
| 13 | start = text.find("{") |
| 14 | end = text.rfind("}") |
| 15 | if start != -1 and end != -1 and end > start: |
| 16 | candidate = text[start : end + 1].strip() |
| 17 | json.loads(candidate) |
| 18 | return candidate |
| 19 | except Exception: |
| 20 | return None |
| 21 | return None |
| 22 | |
| 23 | |
| 24 | def get_latest_user_text(messages: List[Message]) -> str: |
no outgoing calls
no test coverage detected