xiaozhi-esp32-server/xiaozhi-memory/prompts/fact_extraction.py
mkp 0b4d5f594a feat: add LLM memory extraction functionality with OpenAI support
- Implemented a new test script for LLM memory extraction in `test_llm_extraction.py`.
- Created LLM client module with base class `LLMClient` and OpenAI-specific implementation.
- Added fact extraction prompt template for structured memory extraction.
- Integrated memory management with retrieval and intention extraction capabilities.
2026-05-27 22:35:08 +08:00

64 lines
2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
事实提取提示词模板
"""
FACT_EXTRACTION_PROMPT = """你是一个个人信息提取助手。从对话中提取相关事实、记忆、偏好和意图。
CRITICAL 规则(按优先级):
1. TEMPORAL (时间): 始终提取时间信息。将相对时间转换为绝对时间,同时保留原始时间描述
- 例如: "两天后" → "2026-05-28 (两天后)"
- 使用 Observation Date 解析相对时间
2. INTENTIONS (意图): 始终提取用户的意图、需求和请求,即使没有时间信息
- 例如: "我想约个心脏科医生" → 意图记忆
- "明天要去开会" → 意图记忆
3. LANGUAGE (语言): 不要翻译!保持原文语言
- 中文输入 → 中文输出
- 英文输入 → 英文输出
- 混合输入 → 分别保持
4. COMPLETE (完整): 提取完整的事实,包含谁/什么/何时/何地
- 15-80词,上下文丰富
- 包含情感反应、动机
5. SEPARATE (分离): 不同时间段的事实用分开提取
- 不同主题分别提取
6. ATTRIBUTION (归属): 正确归属信息来源
- 用户陈述 → "User ..."
- 助手推荐 → "User was recommended ..."
记忆类型:
- FACT: 已发生的事实("昨天去了北京")
- INTENTION: 未来的计划和意图("明天要去开会")
- PREFERENCE: 偏好("喜欢喝咖啡")
输出格式:
{{
"facts": [
{{
"content": "记忆内容(保持原文语言,15-80词,上下文丰富)",
"type": "FACT|INTENTION|PREFERENCE",
"time_info": {{"absolute": "2026-05-28", "relative": "两天后"}},
"intention_type": "meeting|travel|task|purchase|appointment|...",
"linked_memory_ids": ["uuid1", "uuid2"]
}}
]
}}
如果提取到与现有记忆相关的新记忆,在 linked_memory_ids 中添加相关记忆的ID。
今天的日期: {current_date}
观察日期(用于解析相对时间): {observation_date}
最近提取的记忆:
{recently_extracted}
现有记忆:
{existing_memories}
从以下对话中提取信息:
{conversation}
只返回 JSON,不要其他内容。"""