(payload: Dict[str, Any], response_language: str = "zh")
| 1110 | |
| 1111 | |
| 1112 | def _build_recommendation_reason(payload: Dict[str, Any], response_language: str = "zh") -> str: |
| 1113 | language = _normalize_response_language(response_language) |
| 1114 | reasons: List[str] = [] |
| 1115 | relevance_points = payload.get("relevance_points") or [] |
| 1116 | reading_focus = payload.get("reading_focus") or [] |
| 1117 | analysis_source = _clean_text(payload.get("analysis_source")) |
| 1118 | |
| 1119 | if relevance_points: |
| 1120 | reasons.append(_clean_text(relevance_points[0])) |
| 1121 | if analysis_source == "pdf": |
| 1122 | reasons.append( |
| 1123 | "This run used the full PDF structure, so method and result details are relatively more complete." |
| 1124 | if language == "en" |
| 1125 | else "这次已拿到 PDF 全文结构,方法和结果信息相对更完整。" |
| 1126 | ) |
| 1127 | elif _clean_text(payload.get("analysis_note")): |
| 1128 | reasons.append(_clean_text(payload.get("analysis_note"))) |
| 1129 | if reading_focus: |
| 1130 | reasons.append( |
| 1131 | f"Recommended first focus: {_clean_text(reading_focus[0])}" |
| 1132 | if language == "en" |
| 1133 | else f"建议优先看:{_clean_text(reading_focus[0])}" |
| 1134 | ) |
| 1135 | |
| 1136 | if not reasons: |
| 1137 | reasons.append( |
| 1138 | "This recommendation is mainly based on title, abstract, metadata, and profile matching." |
| 1139 | if language == "en" |
| 1140 | else "当前推荐主要基于题目、摘要、元数据和你的画像匹配结果。" |
| 1141 | ) |
| 1142 | return reasons[0] |
| 1143 | |
| 1144 | |
| 1145 | def _looks_like_placeholder_title(title: str) -> bool: |
no test coverage detected