feat: 更新章节排序逻辑
- 在process_memoir_segments和generate_chapter_content方法中,根据阶段计算章节的排序索引 - 引入CHAPTER_ORDER常量以确保章节顺序的正确性
This commit is contained in:
@@ -21,6 +21,7 @@ from agents.prompts.memory_prompts import (
|
||||
get_creative_title_prompt,
|
||||
get_narrative_prompt,
|
||||
get_state_extraction_prompt,
|
||||
CHAPTER_ORDER,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -262,12 +263,14 @@ def process_memoir_segments(self, user_id: str, segment_ids: List[str]):
|
||||
chapter.is_new = True
|
||||
chapter.source_segments = list({*(chapter.source_segments or []), *source_ids})
|
||||
else:
|
||||
# 根据 stage 计算正确的排序索引
|
||||
calculated_order_index = CHAPTER_ORDER.index(stage) if stage in CHAPTER_ORDER else 999
|
||||
chapter = Chapter(
|
||||
id=str(uuid.uuid4()),
|
||||
user_id=user_id,
|
||||
title=title,
|
||||
content=narrative,
|
||||
order_index=999,
|
||||
order_index=calculated_order_index,
|
||||
status="completed",
|
||||
category=stage,
|
||||
images=[],
|
||||
@@ -363,12 +366,14 @@ def generate_chapter_content(self, user_id: str, stage: str, new_content: str):
|
||||
chapter.content = narrative
|
||||
chapter.is_new = True
|
||||
else:
|
||||
# 根据 stage 计算正确的排序索引
|
||||
calculated_order_index = CHAPTER_ORDER.index(stage) if stage in CHAPTER_ORDER else 999
|
||||
chapter = Chapter(
|
||||
id=str(uuid.uuid4()),
|
||||
user_id=user_id,
|
||||
title=f"{stage} 回忆",
|
||||
content=narrative,
|
||||
order_index=999,
|
||||
order_index=calculated_order_index,
|
||||
status="completed",
|
||||
category=stage,
|
||||
images=[],
|
||||
|
||||
Reference in New Issue
Block a user