fix: 去除LLM直接生成图片占位符逻辑
This commit is contained in:
@@ -10,7 +10,7 @@ from app.core.logging import get_logger
|
||||
|
||||
from app.agents.memoir.prompts import (
|
||||
get_creative_title_prompt,
|
||||
get_narrative_prompt,
|
||||
get_narrative_json_prompt,
|
||||
)
|
||||
|
||||
logger = get_logger(__name__)
|
||||
@@ -61,7 +61,7 @@ class NarrativeAgent:
|
||||
return f"{existing_content}\n\n{new_content}"
|
||||
return new_content
|
||||
try:
|
||||
prompt = get_narrative_prompt(
|
||||
prompt = get_narrative_json_prompt(
|
||||
stage=stage,
|
||||
slots=slots,
|
||||
new_content=new_content,
|
||||
|
||||
@@ -15,7 +15,7 @@ from app.core.task_tracker import task_tracker
|
||||
from app.agents.state_schema import MemoirStateSchema
|
||||
from app.agents.memoir.prompts import (
|
||||
get_creative_title_prompt,
|
||||
get_narrative_prompt,
|
||||
get_narrative_json_prompt,
|
||||
get_state_extraction_prompt,
|
||||
)
|
||||
|
||||
@@ -141,7 +141,7 @@ class MemoirGenerator:
|
||||
return f"{existing_content}\n\n{new_content}"
|
||||
return new_content
|
||||
try:
|
||||
prompt = get_narrative_prompt(
|
||||
prompt = get_narrative_json_prompt(
|
||||
stage=stage,
|
||||
slots=slots,
|
||||
new_content=new_content,
|
||||
|
||||
@@ -349,3 +349,53 @@ def get_narrative_prompt(
|
||||
|
||||
只输出新对话内容的改写结果(包含图片占位符)。如果对话中没有值得记录的人生经历内容,输出空字符串。
|
||||
"""
|
||||
|
||||
|
||||
def get_narrative_json_prompt(
|
||||
stage: str,
|
||||
slots: dict,
|
||||
new_content: str,
|
||||
existing_content: str = "",
|
||||
user_profile: str = "",
|
||||
birth_year: Optional[int] = None,
|
||||
) -> str:
|
||||
"""将新对话改写为叙述,输出 JSON 格式(paragraphs: [{content, image_description}])"""
|
||||
context_tail = ""
|
||||
if existing_content:
|
||||
context_tail = existing_content[-300:] if len(existing_content) > 300 else existing_content
|
||||
context_section = f"\n\n【衔接上下文(已有内容的末尾,仅供参考衔接,不要重复)】:\n{context_tail}" if context_tail else ""
|
||||
profile_section = f"\n\n用户基本信息:\n{user_profile}" if user_profile else ""
|
||||
age_hint = _build_age_hint(stage, birth_year)
|
||||
time_section = f"\n时间参考:{age_hint}" if age_hint else ""
|
||||
|
||||
return f"""{get_system_prompt()}
|
||||
|
||||
请将以下新的对话内容改写为第一人称文学叙述,并输出 **纯 JSON**,不要包含任何其他文字或 markdown 代码块。
|
||||
|
||||
阶段:{stage}
|
||||
可用信息:{slots}{profile_section}{time_section}
|
||||
|
||||
新的对话内容:
|
||||
{new_content}
|
||||
{context_section}
|
||||
|
||||
## 要求
|
||||
1. 从对话中提炼与人生经历相关的核心内容,过滤语气词、寒暄、与AI的交互
|
||||
2. 使用第一人称,改写为流畅的书面叙述,不要直接引用对话原话
|
||||
3. 只输出新内容的改写,不要重复已有内容
|
||||
4. 每 200-300 字左右一个段落,每个段落配一张图
|
||||
5. 如有衔接上下文,确保新内容与之自然衔接
|
||||
|
||||
## 输出格式(严格 JSON)
|
||||
{{
|
||||
"paragraphs": [
|
||||
{{"content": "段落正文", "image_description": "该段配图的场景描述,具体有画面感"}},
|
||||
...
|
||||
]
|
||||
}}
|
||||
|
||||
- content: 本段纯正文,不含占位符
|
||||
- image_description: 该段配图的场景描述,具体、有画面感,便于生成图片。示例:南方小镇的青石板路,两旁是白墙黑瓦的老房子
|
||||
|
||||
如果对话中没有值得记录的人生经历内容,输出:{{"paragraphs": []}}
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user