workos-office / structured_text.py
dellweb3's picture
Enable Kimi primary and task-aware multi-model routing
d31ff90 verified
Raw History Blame Contribute Delete
578 Bytes
"""Decode model JSON wrappers without changing, inventing or dropping document fields."""
import json
import re
def json_object(content):
value=content
for _ in range(5):
if isinstance(value,dict):return value
if isinstance(value,list) and len(value)==1:
value=value[0]
elif isinstance(value,str):
text=re.sub(r'^```(?:json)?\s*|\s*```$','',value.strip(),flags=re.I)
value=json.loads(text,strict=False)
else:raise ValueError('Expected one JSON object')
raise ValueError('Too many JSON wrappers')