mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-10-19 22:17:28 +02:00
ci: cleanup
This commit is contained in:
1 parent
9f7d8d3690
commit
037b50e345
26 files changed
+1377
-455
No files matched your search
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Copy the first JSON object in a model answer to a file.
|
||||
|
||||
python3 .github/scripts/extract-json.py ANSWER_FILE OUTPUT_FILE
|
||||
|
||||
Copilot answers in text. Even when told to return only JSON, a model can wrap
|
||||
it in a markdown fence or put a sentence before it. This skips anything around
|
||||
the first object that parses. Exits 0 when it wrote one, 1 when there is none.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
|
||||
def main() -> int:
|
||||
if len(sys.argv) != 3:
|
||||
print(__doc__, file=sys.stderr)
|
||||
return 2
|
||||
with open(sys.argv[1], encoding="utf-8", errors="replace") as fh:
|
||||
text = fh.read()
|
||||
decoder = json.JSONDecoder()
|
||||
start = text.find("{")
|
||||
while start != -1:
|
||||
try:
|
||||
value, _ = decoder.raw_decode(text, start)
|
||||
except ValueError:
|
||||
start = text.find("{", start + 1)
|
||||
continue
|
||||
if isinstance(value, dict):
|
||||
with open(sys.argv[2], "w", encoding="utf-8") as fh:
|
||||
json.dump(value, fh, ensure_ascii=False)
|
||||
return 0
|
||||
start = text.find("{", start + 1)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user