Reduce LLM rewrite calls and add report intro conclusion
This commit is contained in:
@@ -35,13 +35,28 @@ def _source_link(item: NewsItem) -> str:
|
||||
return source
|
||||
|
||||
|
||||
def _fallback_intro(items: list[NewsItem]) -> str:
|
||||
count = len(items)
|
||||
return f"今天共聚合 {count} 条 AI 动态,覆盖模型能力、产品应用、基础设施、资本与治理等方向。"
|
||||
|
||||
|
||||
def _fallback_conclusion(items: list[NewsItem]) -> str:
|
||||
sections = [section for section in SECTION_ORDER if any(item.section == section for item in items)]
|
||||
if sections:
|
||||
return "总体看,今日 AI 动态主要集中在" + "、".join(sections[:4]) + "等方向,后续仍需持续观察落地进展。"
|
||||
return "总体看,今日 AI 动态仍在持续演进,后续需要关注产品落地和生态变化。"
|
||||
|
||||
|
||||
def assemble_markdown(items: list[NewsItem], guide: dict[str, Any] | None = None) -> tuple[str, dict[str, Any]]:
|
||||
guide = guide or {"theme": "", "threads": []}
|
||||
guide = guide or {"intro": "", "theme": "", "threads": [], "conclusion": ""}
|
||||
lines: list[str] = []
|
||||
|
||||
intro = _ensure_sentence(str(guide.get("intro") or "")) or _fallback_intro(items)
|
||||
lines.extend(["## 引言", "", f"> {intro}", ""])
|
||||
|
||||
theme = _clean_text(str(guide.get("theme") or ""))
|
||||
if theme:
|
||||
lines.extend(["## 导览", "", f"> {theme}", ""])
|
||||
lines.extend(["## 导览", "", f"> {_ensure_sentence(theme)}", ""])
|
||||
|
||||
item_number = 1
|
||||
for section in SECTION_ORDER:
|
||||
@@ -72,6 +87,9 @@ def assemble_markdown(items: list[NewsItem], guide: dict[str, Any] | None = None
|
||||
continue
|
||||
lines.extend([f"- **{title}**", f" {text}", ""])
|
||||
|
||||
conclusion = _ensure_sentence(str(guide.get("conclusion") or "")) or _fallback_conclusion(items)
|
||||
lines.extend(["## 总结", "", f"> {conclusion}", ""])
|
||||
|
||||
markdown = "\n".join(lines).strip()
|
||||
report = validate_markdown(markdown, items)
|
||||
return markdown, report
|
||||
|
||||
Reference in New Issue
Block a user