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

Function _describe_pdf_fallback

agents/reading-agent/main.py:795–827  ·  view source on GitHub ↗
(
    pdf_error: Optional[str],
    *,
    fallback_mode: str = "abstract",
    response_language: str = "zh",
)

Source from the content-addressed store, hash-verified

793
794def _describe_pdf_fallback(
795 pdf_error: Optional[str],
796 *,
797 fallback_mode: str = "abstract",
798 response_language: str = "zh",
799) -> str:
800 is_en = _normalize_response_language(response_language) == "en"
801 lowered = _clean_text(pdf_error).lower()
802 if not lowered:
803 reason = "The PDF full text was unavailable" if is_en else "未能拿到 PDF 全文"
804 elif "403" in lowered or "forbidden" in lowered:
805 reason = "The source blocked PDF access" if is_en else "源站拒绝了 PDF 访问"
806 elif "timed out" in lowered or "timeout" in lowered:
807 reason = "PDF fetching timed out" if is_en else "PDF 抓取超时"
808 elif "ssl" in lowered or "eof" in lowered or "connection" in lowered:
809 reason = "The network connection was unstable while fetching the PDF" if is_en else "PDF 抓取时网络连接不稳定"
810 elif "content-type" in lowered or "did not return a pdf" in lowered:
811 reason = "The source did not return a PDF file directly" if is_en else "源站没有直接返回 PDF 文件"
812 else:
813 reason = "PDF fetching or parsing failed" if is_en else "PDF 抓取或解析失败"
814 if is_en:
815 if fallback_mode == "source_page":
816 return (
817 f"{reason}; this report fell back to the source page text and metadata. "
818 "Verify method and experiment details in the original paper."
819 )
820 return (
821 f"{reason}; this report fell back to the template, abstract, and metadata. "
822 "Verify method and experiment details in the original paper."
823 )
824 if fallback_mode == "source_page":
825 return f"{reason},本次报告已回退为基于源站正文和元数据生成;方法与实验细节仍建议回原文核对。"
826 return f"{reason},本次报告改为按模板基于摘要和元数据生成;方法与实验细节建议回原文核对。"
827
828
829def _recommendation_score(label: str) -> int:
830 normalized = _clean_text(label)

Callers 1

Calls 2

_clean_textFunction · 0.70

Tested by

no test coverage detected