1
0

evidence_bundle.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. """可选:从公开网络拉取简报,作为辩论的「考据附录」(模型仍以自身知识为主)。"""
  2. from __future__ import annotations
  3. from .ddg_search import duckduckgo_search_text
  4. from .wiki_tools import wiki_multiview
  5. def build_evidence_bundle(topic: str, *, max_chars: int = 5500) -> str:
  6. """
  7. 聚合维基多语种摘录 + 少量检索结果,失败时返回说明性短文本。
  8. """
  9. chunks: list[str] = []
  10. try:
  11. w = wiki_multiview(topic.strip())
  12. if len(w) > 4000:
  13. w = w[:4000] + "\n... [维基部分已截断]"
  14. chunks.append("【维基多语种摘录】\n" + w)
  15. except Exception as e: # pragma: no cover
  16. chunks.append(f"【维基】抓取失败:{e}")
  17. try:
  18. q = f"{topic.strip()} 历史 笔记 野史 争议 研究"
  19. chunks.append(duckduckgo_search_text(q, max_results=4, max_body_chars=600))
  20. except Exception as e: # pragma: no cover
  21. chunks.append(f"【检索】失败:{e}")
  22. text = "\n\n---\n\n".join(chunks)
  23. if len(text) > max_chars:
  24. text = text[:max_chars] + "\n... [总附录已截断]"
  25. return text