Merge remote-tracking branch 'origin/development' into development
# Conflicts: # api/agents/prompts/memory_prompts.py
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
回忆录整理 Agent 提示词模板
|
||||
"""
|
||||
import json
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
# 章节分类映射
|
||||
@@ -43,6 +44,47 @@ STAGE_TO_ORDER = {
|
||||
"summary": 7,
|
||||
}
|
||||
|
||||
# 图片占位符入库前拼接的固定提示词模板(与原先 prompt 中要求一致,改为代码侧统一拼接)
|
||||
IMAGE_PLACEHOLDER_TEMPLATE = (
|
||||
"温暖怀旧风格,人生章节封面,年代感复古色调,柔和光影,朴素温馨氛围,安静治愈,低饱和度,"
|
||||
"质感柔和细腻,简约构图,充满岁月沉淀感与故事感,高清唯美插画封面,不要包含文字,"
|
||||
"要适合老年人阅读风格,要有年代感。"
|
||||
)
|
||||
|
||||
|
||||
def inject_image_placeholder_template(content: str) -> str:
|
||||
"""
|
||||
入库前对章节正文做占位符处理:用正则匹配所有图片占位符位置,拼上固定模板。
|
||||
支持 {{IMAGE:...}} 与 {{{{IMAGE:...}}}} 两种格式,输出统一为四层大括号 + 固定模板 + 描述。
|
||||
若占位符内已包含固定模板前缀则不再重复拼接,保证位置与逻辑与原先一致。
|
||||
"""
|
||||
if not content or not content.strip():
|
||||
return content
|
||||
|
||||
def replace_one(match: re.Match) -> str:
|
||||
inner = match.group(1).strip()
|
||||
if not inner:
|
||||
return match.group(0)
|
||||
if inner.startswith(IMAGE_PLACEHOLDER_TEMPLATE):
|
||||
desc = inner[len(IMAGE_PLACEHOLDER_TEMPLATE):].lstrip("。").strip()
|
||||
return "{{{{IMAGE:" + IMAGE_PLACEHOLDER_TEMPLATE + ("。" + desc if desc else "") + "}}}}"
|
||||
return "{{{{IMAGE:" + IMAGE_PLACEHOLDER_TEMPLATE + "。" + inner + "}}}}"
|
||||
|
||||
# 四层大括号
|
||||
content = re.sub(
|
||||
r"\{\{\{\{IMAGE:\s*([^}]+)\}\}\}\}",
|
||||
replace_one,
|
||||
content,
|
||||
flags=re.DOTALL,
|
||||
)
|
||||
# 两层大括号(兼容旧格式)
|
||||
content = re.sub(
|
||||
r"\{\{IMAGE:\s*([^}]+)\}\}",
|
||||
replace_one,
|
||||
content,
|
||||
flags=re.DOTALL,
|
||||
)
|
||||
return content
|
||||
def get_system_prompt() -> str:
|
||||
"""获取整理 Agent 的系统提示词"""
|
||||
return """你是一位专业的传记作家和文字编辑,擅长将口语化的对话内容整理成优雅的书面语回忆录章节。
|
||||
@@ -142,14 +184,12 @@ def get_text_rewrite_prompt(segments_text: str, chapter_category: str, existing_
|
||||
4. 在内容中适当位置插入图片占位符
|
||||
|
||||
## 图片占位符格式
|
||||
在描述场景、人物、重要时刻的段落后,插入:
|
||||
{{{{IMAGE:具体的图片描述}}}}
|
||||
在描述场景、人物、重要时刻的段落后,插入占位符,格式为:{{{{IMAGE:具体的图片描述}}}}
|
||||
占位符单独占一行,描述要具体、有画面感。系统会在入库前自动拼上统一风格模板,你只需写场景描述即可。
|
||||
|
||||
示例:
|
||||
{{{{IMAGE:南方小镇的青石板路,两旁是白墙黑瓦的老房子}}}}
|
||||
{{{{IMAGE:奶奶坐在院子里的藤椅上,手里摇着蒲扇}}}}
|
||||
|
||||
占位符单独占一行,描述要具体有画面感。"""
|
||||
{{{{IMAGE:奶奶坐在院子里的藤椅上,手里摇着蒲扇}}}}"""
|
||||
|
||||
|
||||
def get_state_extraction_prompt(user_message: str, current_stage: str, stage_slots: dict) -> str:
|
||||
@@ -305,8 +345,8 @@ def get_narrative_prompt(
|
||||
9. **不要在正文中插入章节标题或分类标签**(如"章节:信念与价值观"、"## 童年与成长背景"等),章节标题由系统单独管理
|
||||
|
||||
## 图片占位符格式
|
||||
在描述场景、人物、重要时刻的段落后,插入图片占位符,格式为:
|
||||
{{{{IMAGE:图片描述}}}}
|
||||
在描述场景、人物、重要时刻的段落后,插入占位符,格式为:{{{{IMAGE:具体的图片描述}}}}
|
||||
占位符单独占一行,描述要具体、有画面感。系统会在入库前自动拼上统一风格模板,你只需写场景描述即可。
|
||||
|
||||
示例:
|
||||
- {{{{IMAGE:南方小镇的青石板路,两旁是白墙黑瓦的老房子}}}}
|
||||
|
||||
Reference in New Issue
Block a user