Spaces:
Paused
Paused
import json | |
import os | |
from langchain_core.messages import AIMessage | |
from typing import List, Dict, Tuple | |
import re | |
def extract_json(message: AIMessage) -> List[dict]: | |
text = message.content | |
pattern = r"```json(.*?)```" | |
matches = re.findall(pattern, text, re.DOTALL) | |
try: | |
return [json.loads(match.strip()) for match in matches] | |
except Exception: | |
raise ValueError(f"Failed to parse: {message}") |