Simplify AI memory pipeline
This commit is contained in:
@@ -81,15 +81,11 @@ def format_user_memory_for_chat_display(
|
||||
|
||||
|
||||
def format_evidence_chunks_for_chat_prompt(evidence: dict) -> str:
|
||||
"""聊天访谈专用:将检索 bundle 格式化为带编号引用与安全说明的短文本。
|
||||
|
||||
与 `format_evidence_chunks_for_prompt` 并行存在;memoir/叙事流水线仍用后者,避免牵连成稿。
|
||||
"""
|
||||
"""聊天访谈专用:将检索 bundle 格式化为带编号引用与安全说明的短文本."""
|
||||
chunks = evidence.get("relevant_chunks") or []
|
||||
chunks = dedupe_evidence_chunk_rows(chunks[:10])
|
||||
summaries = evidence.get("relevant_summaries") or []
|
||||
facts = evidence.get("relevant_facts") or []
|
||||
timeline = evidence.get("timeline_hints") or []
|
||||
stories = evidence.get("relevant_stories") or []
|
||||
|
||||
header = (
|
||||
@@ -143,20 +139,6 @@ def format_evidence_chunks_for_chat_prompt(evidence: dict) -> str:
|
||||
safe = format_user_memory_for_chat_display(fact_line)
|
||||
lines.append(f"[M{n}] {safe}")
|
||||
|
||||
for t in timeline[:5]:
|
||||
if isinstance(t, dict):
|
||||
title = (t.get("title") or "").strip()
|
||||
year = t.get("event_year")
|
||||
desc = (t.get("description") or "").strip()
|
||||
line = " ".join(
|
||||
x for x in (str(year) if year is not None else "", title, desc) if x
|
||||
)
|
||||
if not line:
|
||||
continue
|
||||
n += 1
|
||||
safe = format_user_memory_for_chat_display(line)
|
||||
lines.append(f"[M{n}] {safe}")
|
||||
|
||||
for st in stories[:3]:
|
||||
if isinstance(st, dict):
|
||||
title = (st.get("title") or "").strip()
|
||||
@@ -175,15 +157,11 @@ def format_evidence_chunks_for_chat_prompt(evidence: dict) -> str:
|
||||
|
||||
|
||||
def format_evidence_chunks_for_prompt(evidence: dict) -> str:
|
||||
"""将 MemoryService.retrieve 结果格式化为简短文本,供叙事与访谈 prompt 使用。
|
||||
|
||||
包含 chunks、摘要(若有)、confirmed facts、timeline、故事摘要(若有)。
|
||||
"""
|
||||
"""将 MemoryService.retrieve 结果格式化为简短文本,供叙事与访谈 prompt 使用."""
|
||||
chunks = evidence.get("relevant_chunks") or []
|
||||
chunks = dedupe_evidence_chunk_rows(chunks[:10])
|
||||
summaries = evidence.get("relevant_summaries") or []
|
||||
facts = evidence.get("relevant_facts") or []
|
||||
timeline = evidence.get("timeline_hints") or []
|
||||
stories = evidence.get("relevant_stories") or []
|
||||
parts: list[str] = []
|
||||
for c in chunks:
|
||||
@@ -212,16 +190,6 @@ def format_evidence_chunks_for_prompt(evidence: dict) -> str:
|
||||
parts.append(f"{subj}:{pred}")
|
||||
else:
|
||||
parts.append(f"{getattr(f, 'subject', '')}:{getattr(f, 'predicate', '')}")
|
||||
for t in timeline[:5]:
|
||||
if isinstance(t, dict):
|
||||
title = (t.get("title") or "").strip()
|
||||
year = t.get("event_year")
|
||||
desc = (t.get("description") or "").strip()
|
||||
line = " ".join(
|
||||
x for x in (str(year) if year is not None else "", title, desc) if x
|
||||
)
|
||||
if line:
|
||||
parts.append(line)
|
||||
for st in stories[:3]:
|
||||
if isinstance(st, dict):
|
||||
title = (st.get("title") or "").strip()
|
||||
|
||||
Reference in New Issue
Block a user