44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
import json
|
|
|
|
|
|
def to_markdown(result: dict) -> str:
|
|
if "error" in result:
|
|
return "# Deep Research\n\n**Error:** " + result["error"]
|
|
|
|
lines = ["# Deep Research", "", "**Question:** " + result.get("question", ""), ""]
|
|
lines += ["## Summary", result.get("summary", ""), ""]
|
|
|
|
findings = result.get("findings", [])
|
|
if findings:
|
|
lines.append("## Findings")
|
|
for i, f in enumerate(findings, 1):
|
|
srcs = ", ".join(f.get("sources", []))
|
|
lines += [
|
|
f"### {i}. {f['claim']} _({f['confidence']})_",
|
|
f"{f.get('evidence', '')}",
|
|
f"Sources: {srcs}",
|
|
"",
|
|
]
|
|
|
|
caveats = result.get("caveats")
|
|
if caveats:
|
|
lines += ["## Caveats", caveats, ""]
|
|
|
|
oq = result.get("openQuestions")
|
|
if oq:
|
|
lines += ["## Open Questions"] + [f"- {q}" for q in oq] + [""]
|
|
|
|
refuted = result.get("refuted", [])
|
|
if refuted:
|
|
lines.append("## Refuted (transparency)")
|
|
for r in refuted:
|
|
lines.append(f"- \"{r['claim']}\" (vote {r.get('vote', '')}, {r.get('source', '')})")
|
|
lines.append("")
|
|
|
|
lines += ["## Stats", "```json", json.dumps(result.get("stats", {}), ensure_ascii=False, indent=2), "```"]
|
|
return "\n".join(lines)
|
|
|
|
|
|
def to_json(result: dict) -> str:
|
|
return json.dumps(result, ensure_ascii=False, indent=2)
|