MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / build_heuristic_report_payload

Function build_heuristic_report_payload

agents/reading-agent/main.py:3878–4134  ·  view source on GitHub ↗
(
    paper: Dict[str, Any],
    user_profile: Dict[str, Any],
    parsed_pdf: Optional[Dict[str, Any]] = None,
    pdf_error: Optional[str] = None,
    response_language: str = "zh",
)

Source from the content-addressed store, hash-verified

3876
3877
3878def build_heuristic_report_payload(
3879 paper: Dict[str, Any],
3880 user_profile: Dict[str, Any],
3881 parsed_pdf: Optional[Dict[str, Any]] = None,
3882 pdf_error: Optional[str] = None,
3883 response_language: str = "zh",
3884) -> Dict[str, Any]:
3885 language = _normalize_response_language(response_language)
3886 is_en = language == "en"
3887 sections = dict((parsed_pdf or {}).get("sections") or {})
3888 parsed_source_kind = _clean_text((parsed_pdf or {}).get("source_kind")).lower() or ("pdf" if parsed_pdf else "abstract")
3889 if _prefer_candidate_abstract(paper.get("abstract"), (parsed_pdf or {}).get("abstract")):
3890 abstract = _clean_abstract_text((parsed_pdf or {}).get("abstract"))
3891 else:
3892 abstract = _clean_abstract_text(_first_non_empty(paper.get("abstract"), (parsed_pdf or {}).get("abstract")))
3893 introduction = _truncate_text(sections.get("introduction"), MAX_SECTION_CHARS)
3894 method = _truncate_text(sections.get("method"), MAX_SECTION_CHARS)
3895 results = _truncate_text(sections.get("results"), MAX_SECTION_CHARS)
3896 discussion = _truncate_text(sections.get("discussion"), MAX_SECTION_CHARS)
3897 conclusion = _truncate_text(sections.get("conclusion"), MAX_SECTION_CHARS)
3898 retrieved_evidence = _retrieve_report_evidence(paper, user_profile, parsed_pdf)
3899
3900 # 优先使用 PDF 切块后的语义检索证据,其次回退到章节摘要/abstract 启发式
3901 bg_from_evidence = " ".join(_collect_evidence_sentences(retrieved_evidence, "background", limit=2))
3902 bg_from_pdf = " ".join(_pick_sentences(introduction, limit=2)) if introduction else ""
3903 bg_from_abstract = _infer_section_from_abstract(abstract, "background")
3904 research_background = _first_non_empty(bg_from_evidence, bg_from_pdf, bg_from_abstract)
3905 if not research_background:
3906 research_background = (
3907 "Start with the original abstract and introduction to understand the research background."
3908 if is_en
3909 else "建议先查看原文摘要和引言部分以了解研究背景。"
3910 )
3911
3912 method_from_evidence = " ".join(
3913 _collect_evidence_sentences(
3914 retrieved_evidence,
3915 "method",
3916 limit=2,
3917 cues=CONTRIBUTION_CUES,
3918 )
3919 )
3920 method_from_pdf = " ".join(_pick_sentences(method, limit=2, cues=CONTRIBUTION_CUES)) if method else ""
3921 method_from_abstract = _infer_section_from_abstract(abstract, "method")
3922 core_method = _first_non_empty(method_from_evidence, method_from_pdf, method_from_abstract)
3923 if not core_method:
3924 core_method = (
3925 "Method details were not extracted reliably; focus on the Method / Approach section in the original paper."
3926 if is_en
3927 else "方法细节建议重点查看原文的 Method / Approach 部分。"
3928 )
3929
3930 results_from_evidence = " ".join(
3931 _collect_evidence_sentences(
3932 retrieved_evidence,
3933 "results",
3934 limit=2,
3935 cues=RESULT_CUES,

Callers 2

generate_reading_reportFunction · 0.85
build_pending_reportFunction · 0.85

Calls 15

_first_non_emptyFunction · 0.85
_truncate_textFunction · 0.85
_pick_sentencesFunction · 0.85
_unique_preserve_orderFunction · 0.85
_append_analysis_noteFunction · 0.85
_describe_pdf_fallbackFunction · 0.85

Tested by

no test coverage detected