distill: salvage well-formed strings from malformed writer arrays
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
07a0db6b61
commit
2b3b6e8dfd
@ -96,7 +96,15 @@ def ask_writer(persona, topic, refs):
|
||||
start = txt.find("[")
|
||||
if start < 0:
|
||||
raise ValueError(f"no JSON array in writer output: {txt[:200]}")
|
||||
try:
|
||||
arr, _ = json.JSONDecoder().raw_decode(txt[start:])
|
||||
except json.JSONDecodeError:
|
||||
# salvage: models sometimes break an array element mid-list;
|
||||
# harvest the well-formed quoted strings instead of losing all 12
|
||||
arr = [json.loads(f'"{m}"') for m in
|
||||
re.findall(r'"((?:[^"\\]|\\.){8,300})"', txt[start:])]
|
||||
if not arr:
|
||||
raise
|
||||
except (ValueError, json.JSONDecodeError) as e:
|
||||
last_err = e
|
||||
continue
|
||||
|
||||
Loading…
Reference in New Issue
Block a user