重试生成单张图片 Args: task_id: 任务ID page: 页面数据 use_reference: 是否使用封面作为参考 full_outline: 完整大纲文本(从前端传入) user_topic: 用户原始输入(从前端传入) Returns: 生成结果
(
self,
task_id: str,
page: Dict,
use_reference: bool = True,
full_outline: str = "",
user_topic: str = "",
record_id: Optional[str] = None
)
| 623 | return events |
| 624 | |
| 625 | def retry_single_image( |
| 626 | self, |
| 627 | task_id: str, |
| 628 | page: Dict, |
| 629 | use_reference: bool = True, |
| 630 | full_outline: str = "", |
| 631 | user_topic: str = "", |
| 632 | record_id: Optional[str] = None |
| 633 | ) -> Dict[str, Any]: |
| 634 | """ |
| 635 | 重试生成单张图片 |
| 636 | |
| 637 | Args: |
| 638 | task_id: 任务ID |
| 639 | page: 页面数据 |
| 640 | use_reference: 是否使用封面作为参考 |
| 641 | full_outline: 完整大纲文本(从前端传入) |
| 642 | user_topic: 用户原始输入(从前端传入) |
| 643 | |
| 644 | Returns: |
| 645 | 生成结果 |
| 646 | """ |
| 647 | self.current_task_dir = os.path.join(self.history_root_dir, task_id) |
| 648 | os.makedirs(self.current_task_dir, exist_ok=True) |
| 649 | |
| 650 | reference_image = None |
| 651 | user_images = None |
| 652 | |
| 653 | # 首先尝试从任务状态中获取上下文 |
| 654 | if task_id in self._task_states: |
| 655 | task_state = self._task_states[task_id] |
| 656 | if use_reference: |
| 657 | reference_image = task_state.get("cover_image") |
| 658 | # 如果没有传入上下文,则使用任务状态中的 |
| 659 | if not full_outline: |
| 660 | full_outline = task_state.get("full_outline", "") |
| 661 | if not user_topic: |
| 662 | user_topic = task_state.get("user_topic", "") |
| 663 | user_images = task_state.get("user_images") |
| 664 | |
| 665 | # 如果任务状态中没有封面图,尝试从文件系统加载 |
| 666 | if use_reference and reference_image is None: |
| 667 | cover_path = os.path.join(self.current_task_dir, "0.png") |
| 668 | if os.path.exists(cover_path): |
| 669 | with open(cover_path, "rb") as f: |
| 670 | cover_data = f.read() |
| 671 | # 压缩封面图到 200KB |
| 672 | reference_image = compress_image(cover_data, max_size_kb=200) |
| 673 | |
| 674 | total_count = None |
| 675 | if task_id in self._task_states: |
| 676 | total_count = len(self._task_states[task_id].get("pages", [])) |
| 677 | |
| 678 | index, success, filename, error = self._generate_single_image( |
| 679 | page, |
| 680 | task_id, |
| 681 | reference_image, |
| 682 | 0, |
no test coverage detected