23 lines
703 B
Python
23 lines
703 B
Python
"""解析模型返回为小周天记忆候选 + 反思(纯函数,无 IO)。
|
||
|
||
模型输出对象 ``{"memories": [...], "reflection": str}``。记忆候选解析复用 extraction
|
||
的 ``parse_memory_drafts``;``reflection`` 为本轮复盘文本。
|
||
"""
|
||
|
||
from app.modules.extraction.extract import (
|
||
MemoryCandidateDraft,
|
||
extract_json_object,
|
||
parse_memory_drafts,
|
||
)
|
||
|
||
|
||
def parse_reflection(
|
||
raw: str,
|
||
) -> tuple[list[MemoryCandidateDraft], str]:
|
||
data = extract_json_object(raw)
|
||
if not isinstance(data, dict):
|
||
return [], ""
|
||
memories = parse_memory_drafts(data.get("memories"))
|
||
reflection = str(data.get("reflection", "")).strip()
|
||
return memories, reflection
|