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

Function create_reading_report

agents/reading-agent/main.py:4775–5128  ·  view source on GitHub ↗
(
    user_id: str,
    paper_ids: List[int],
    papers: List[Dict],
    folder_id: Optional[str] = None,
    send_to_feishu: bool = True,
    feishu_user_id: Optional[str] = None,
    chat_id: Optional[str] = None,
    request_metadata: Optional[Dict[str, Any]] = None,
)

Source from the content-addressed store, hash-verified

4773
4774def create_reading_report(
4775 user_id: str,
4776 paper_ids: List[int],
4777 papers: List[Dict],
4778 folder_id: Optional[str] = None,
4779 send_to_feishu: bool = True,
4780 feishu_user_id: Optional[str] = None,
4781 chat_id: Optional[str] = None,
4782 request_metadata: Optional[Dict[str, Any]] = None,
4783) -> List[Dict[str, Any]]:
4784 print(f"Creating reading reports for user: {user_id}")
4785 print(f"Selected papers: {paper_ids}")
4786
4787 target_id = chat_id or feishu_user_id
4788 use_chat_id = chat_id is not None
4789 request_metadata = dict(request_metadata or {})
4790 report_style = _normalize_report_style(request_metadata.get("report_style"))
4791 response_language = _normalize_response_language(request_metadata.get("response_language"))
4792 request_metadata["response_language"] = response_language
4793
4794 profile = get_profile(user_id)
4795 if not profile:
4796 print(f"Warning: No profile found for user {user_id}, using default")
4797 profile = {"core_directions": {}, "methodology_preferences": {}}
4798 profile = ensure_profile_schema(profile)
4799
4800 selected_papers = resolve_selected_papers(paper_ids, papers)
4801 if not selected_papers:
4802 print("No valid papers selected")
4803 if send_to_feishu and target_id:
4804 send_text(
4805 target_id,
4806 "这次没有找到可生成精读的论文,请先推送后回复编号,或重新发送“精读”。",
4807 use_chat_id=use_chat_id,
4808 )
4809 return []
4810
4811 # 1. If this request comes from a specific uploaded PDF, reuse the existing
4812 # report when the same source key has already been processed successfully.
4813 existing_pdf_doc = None
4814 if request_metadata.get("report_source_type") and request_metadata.get("report_source_key"):
4815 existing_pdf_doc = _lookup_existing_pdf_report(user_id, request_metadata, selected_papers[0])
4816 if existing_pdf_doc:
4817 print(
4818 "Reusing existing PDF reading report for "
4819 f"{request_metadata.get('report_source_type')}={request_metadata.get('report_source_key')}"
4820 )
4821 if send_to_feishu and target_id:
4822 summary_text = format_created_docs_summary([existing_pdf_doc])
4823 try:
4824 send_text(target_id, summary_text, use_chat_id=use_chat_id)
4825 print(f"\nNotification sent to Feishu target: {target_id}")
4826 except Exception as exc:
4827 print(f"\nFailed to send reused PDF doc summary to Feishu: {exc}")
4828 return [existing_pdf_doc]
4829
4830 # 2. For pushed/selected papers, reuse already-created docs by paper_id and
4831 # only generate reports for the missing subset.
4832 existing_reports_by_paper_id: Dict[int, Dict[str, Any]] = {}

Callers 2

main.pyFile · 0.85

Tested by

no test coverage detected