Reduce LLM rewrite calls and add report intro conclusion
This commit is contained in:
@@ -23,8 +23,10 @@ def _clean_text(text: str, limit: int | None = None) -> str:
|
||||
def _build_prompt(items: list[NewsItem]) -> str:
|
||||
payload = {
|
||||
"task": (
|
||||
"Generate a concise AI daily report guide. Return JSON only. Do not use 强信号/中信号/待验证. "
|
||||
"Use a short theme and 2-4 daily threads. Every thread must reference existing item_ids."
|
||||
"Generate a concise Chinese AI daily report guide. Return JSON only. "
|
||||
"Do not use 强信号/中信号/待验证. Do not add facts. "
|
||||
"Write one opening intro, a short theme, 2-4 daily threads, and one closing conclusion. "
|
||||
"Every thread must reference existing item_ids."
|
||||
),
|
||||
"items": [
|
||||
{
|
||||
@@ -37,6 +39,7 @@ def _build_prompt(items: list[NewsItem]) -> str:
|
||||
for item in items
|
||||
],
|
||||
"output_schema": {
|
||||
"intro": "one opening paragraph under 160 Chinese characters",
|
||||
"theme": "one sentence under 120 Chinese characters",
|
||||
"threads": [
|
||||
{
|
||||
@@ -46,23 +49,27 @@ def _build_prompt(items: list[NewsItem]) -> str:
|
||||
"kind": "thread|uncertain",
|
||||
}
|
||||
],
|
||||
"conclusion": "one closing paragraph under 180 Chinese characters",
|
||||
},
|
||||
}
|
||||
return json.dumps(payload, ensure_ascii=False)
|
||||
|
||||
|
||||
def _empty_guide() -> dict[str, Any]:
|
||||
return {"intro": "", "theme": "", "threads": [], "conclusion": ""}
|
||||
|
||||
|
||||
def generate_guide(
|
||||
items: list[NewsItem],
|
||||
*,
|
||||
llm_call: GuideLlmCall,
|
||||
) -> tuple[dict[str, Any], dict[str, Any]]:
|
||||
if not items:
|
||||
return {
|
||||
"theme": "",
|
||||
"threads": [],
|
||||
}, {
|
||||
return _empty_guide(), {
|
||||
"input_count": 0,
|
||||
"intro_present": False,
|
||||
"theme_present": False,
|
||||
"conclusion_present": False,
|
||||
"thread_count": 0,
|
||||
"dropped_thread_count": 0,
|
||||
"fallback_used": False,
|
||||
@@ -72,12 +79,11 @@ def generate_guide(
|
||||
try:
|
||||
obj = parse_json_object(llm_call(_build_prompt(items)))
|
||||
except Exception as exc:
|
||||
return {
|
||||
"theme": "",
|
||||
"threads": [],
|
||||
}, {
|
||||
return _empty_guide(), {
|
||||
"input_count": len(items),
|
||||
"intro_present": False,
|
||||
"theme_present": False,
|
||||
"conclusion_present": False,
|
||||
"thread_count": 0,
|
||||
"dropped_thread_count": 0,
|
||||
"fallback_used": True,
|
||||
@@ -100,11 +106,15 @@ def generate_guide(
|
||||
kind = thread.get("kind") if thread.get("kind") in ("thread", "uncertain") else "thread"
|
||||
threads.append({"title": title, "text": text, "item_ids": item_ids, "kind": kind})
|
||||
|
||||
intro = _clean_text(str(obj.get("intro") or ""), limit=160)
|
||||
theme = _clean_text(str(obj.get("theme") or ""), limit=120)
|
||||
guide = {"theme": theme, "threads": threads}
|
||||
conclusion = _clean_text(str(obj.get("conclusion") or ""), limit=180)
|
||||
guide = {"intro": intro, "theme": theme, "threads": threads, "conclusion": conclusion}
|
||||
report = {
|
||||
"input_count": len(items),
|
||||
"intro_present": bool(intro),
|
||||
"theme_present": bool(theme),
|
||||
"conclusion_present": bool(conclusion),
|
||||
"thread_count": len(threads),
|
||||
"dropped_thread_count": dropped,
|
||||
"fallback_used": False,
|
||||
|
||||
Reference in New Issue
Block a user