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

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