refactor: render response as plaintext with newlines, fallback to JSON pretty-print
Co-authored-by: aider (o3) <aider@aider.chat>
This commit is contained in:
@@ -50,10 +50,15 @@ def pretty_print_jsonl(path: Path, indent: int) -> None:
|
|||||||
obj = json.loads(line)
|
obj = json.loads(line)
|
||||||
except json.JSONDecodeError as exc:
|
except json.JSONDecodeError as exc:
|
||||||
sys.exit(f"JSON decode error on line {idx}: {exc}") # fail fast
|
sys.exit(f"JSON decode error on line {idx}: {exc}") # fail fast
|
||||||
# Build pretty JSON string, convert literal "\n" sequences to real newlines,
|
# Prefer rendering the `response` field as plain-text, expanding literal
|
||||||
# and emit a blank line between records for readability.
|
# "\n" sequences to real newlines. Fall back to JSON pretty-print if the
|
||||||
|
# key is missing so we still show *something* useful.
|
||||||
|
if "response" in obj:
|
||||||
|
response_text = str(obj["response"]).replace("\\n", "\n")
|
||||||
|
sys.stdout.write(response_text)
|
||||||
|
sys.stdout.write("\n\n")
|
||||||
|
else:
|
||||||
pretty = json.dumps(obj, indent=indent, ensure_ascii=False, sort_keys=True)
|
pretty = json.dumps(obj, indent=indent, ensure_ascii=False, sort_keys=True)
|
||||||
pretty = pretty.replace("\\n", "\n")
|
|
||||||
sys.stdout.write(pretty)
|
sys.stdout.write(pretty)
|
||||||
sys.stdout.write("\n\n")
|
sys.stdout.write("\n\n")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user