mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-06-02 00:57:41 +08:00
feat(dream): add memory dream cli and docs
- New memory/deep-dream.mdx (zh/en/ja): memory flow, distillation rules, dream diary, manual trigger, safety mechanisms - Simplify long-term memory page, link to deep-dream for details - New cli/memory-knowledge.mdx (zh/en/ja): memory and knowledge commands - Move knowledge commands from general.mdx to memory-knowledge.mdx - Register new pages in docs.json navigation for all languages - Add /memory dream to cli/index.mdx command tables
This commit is contained in:
@@ -42,7 +42,7 @@ DREAM_SYSTEM_PROMPT = """你是一个记忆整理助手,负责定期整理用
|
||||
1. **当前长期记忆** — MEMORY.md 的全部现有内容
|
||||
2. **今日日记** — 当天的日常记录
|
||||
|
||||
MEMORY.md 会注入每次对话的系统提示词中,因此必须保持精炼。
|
||||
MEMORY.md 会注入每次对话的系统提示词中,因此必须保持精炼,只存放有价值和值得记忆的内容。
|
||||
|
||||
**重要:只能基于提供的材料进行整理,严禁编造、推测或添加材料中不存在的信息。**
|
||||
|
||||
@@ -52,12 +52,12 @@ MEMORY.md 会注入每次对话的系统提示词中,因此必须保持精炼
|
||||
|
||||
在现有记忆基础上进行整理和提炼,输出完整的更新后内容:
|
||||
- **合并提炼**:将含义相近的多条合并为一条高密度表述,而非简单罗列
|
||||
- **新增萃取**:从今日日记中提取值得永久记住的新信息(偏好、决策、人物、经验)
|
||||
- **新增萃取**:从今日日记中提取值得永久记住的新信息(偏好、决策、人物、规则、经验)
|
||||
- **冲突更新**:当新信息与旧条目矛盾时,以新信息为准,替换旧条目
|
||||
- **清理无效**:删除临时性记录、空白条目、格式残留等
|
||||
- **删除冗余**:已被更精炼表述涵盖的旧条目应删除,避免信息重复
|
||||
- 每条一行,用 "- " 开头,不带日期前缀
|
||||
- 目标:控制在 30 条以内,每条尽量一句话概括
|
||||
- 目标:控制在 50 条以内,每条尽量一句话概括
|
||||
|
||||
### Part 2: 梦境日记([DREAM])
|
||||
|
||||
@@ -300,15 +300,13 @@ class MemoryFlushManager:
|
||||
|
||||
# ---- Deep Dream (memory distillation) ----
|
||||
|
||||
def deep_dream(self, user_id: Optional[str] = None, lookback_days: int = 1) -> bool:
|
||||
def deep_dream(self, user_id: Optional[str] = None, lookback_days: int = 1, force: bool = False) -> bool:
|
||||
"""
|
||||
Distill recent daily memories into MEMORY.md and generate a dream diary.
|
||||
|
||||
Process:
|
||||
1. Read current MEMORY.md + recent N days of daily files
|
||||
2. LLM produces updated MEMORY.md (deduped/pruned) + dream diary narrative
|
||||
3. Overwrite MEMORY.md with the distilled version
|
||||
4. Write dream diary to memory/dreams/YYYY-MM-DD.md
|
||||
Args:
|
||||
lookback_days: How many days of daily files to read (default 1 for scheduled, 3 for manual)
|
||||
force: Skip input-hash dedup check (used by manual /memory dream trigger)
|
||||
"""
|
||||
if not self.llm_model:
|
||||
logger.warning("[DeepDream] No LLM model available, skipping")
|
||||
@@ -327,7 +325,7 @@ class MemoryFlushManager:
|
||||
# Dedup: skip if input materials haven't changed since last dream
|
||||
import hashlib
|
||||
input_hash = hashlib.md5((memory_content + daily_content).encode("utf-8")).hexdigest()
|
||||
if input_hash == self._last_dream_input_hash:
|
||||
if not force and input_hash == self._last_dream_input_hash:
|
||||
logger.debug("[DeepDream] Input unchanged since last dream, skipping")
|
||||
return False
|
||||
self._last_dream_input_hash = input_hash
|
||||
@@ -377,16 +375,10 @@ class MemoryFlushManager:
|
||||
logger.warning("[DeepDream] No [MEMORY] section in LLM output, skipping overwrite")
|
||||
return False
|
||||
|
||||
# Overwrite MEMORY.md (with shrinkage protection)
|
||||
# Overwrite MEMORY.md
|
||||
try:
|
||||
main_file = self.get_main_memory_file(user_id)
|
||||
old_size = len(memory_content)
|
||||
if old_size > 200 and len(new_memory) < old_size * 0.3:
|
||||
logger.warning(
|
||||
f"[DeepDream] Distilled MEMORY.md is too small "
|
||||
f"({old_size} → {len(new_memory)} chars, <30%), aborting to prevent data loss"
|
||||
)
|
||||
return False
|
||||
main_file.write_text(new_memory + "\n", encoding="utf-8")
|
||||
logger.info(
|
||||
f"[DeepDream] Updated MEMORY.md "
|
||||
|
||||
Reference in New Issue
Block a user