diff --git a/api/tasks/memoir_tasks.py b/api/tasks/memoir_tasks.py index dd81923..d3d6029 100644 --- a/api/tasks/memoir_tasks.py +++ b/api/tasks/memoir_tasks.py @@ -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=[],