MCPcopy
hub / github.com/HisMax/RedInk / _generate_single_image

Method _generate_single_image

backend/services/image.py:138–245  ·  view source on GitHub ↗

生成单张图片(带自动重试) Args: page: 页面数据 task_id: 任务ID reference_image: 参考图片(封面图) retry_count: 当前重试次数 full_outline: 完整的大纲文本 user_images: 用户上传的参考图片列表 user_topic: 用户原始输入 Returns: (index, su

(
        self,
        page: Dict,
        task_id: str,
        reference_image: Optional[bytes] = None,
        retry_count: int = 0,
        full_outline: str = "",
        user_images: Optional[List[bytes]] = None,
        user_topic: str = "",
        record_id: Optional[str] = None,
        total_count: Optional[int] = None
    )

Source from the content-addressed store, hash-verified

136 return filepath
137
138 def _generate_single_image(
139 self,
140 page: Dict,
141 task_id: str,
142 reference_image: Optional[bytes] = None,
143 retry_count: int = 0,
144 full_outline: str = "",
145 user_images: Optional[List[bytes]] = None,
146 user_topic: str = "",
147 record_id: Optional[str] = None,
148 total_count: Optional[int] = None
149 ) -> Tuple[int, bool, Optional[str], Optional[str]]:
150 """
151 生成单张图片(带自动重试)
152
153 Args:
154 page: 页面数据
155 task_id: 任务ID
156 reference_image: 参考图片(封面图)
157 retry_count: 当前重试次数
158 full_outline: 完整的大纲文本
159 user_images: 用户上传的参考图片列表
160 user_topic: 用户原始输入
161
162 Returns:
163 (index, success, filename, error_message)
164 """
165 index = page["index"]
166 page_type = page["type"]
167 page_content = page["content"]
168
169 try:
170 logger.debug(f"生成图片 [{index}]: type={page_type}")
171
172 # 根据配置选择模板(短 prompt 或完整 prompt)
173 if self.use_short_prompt and self.prompt_template_short:
174 # 短 prompt 模式:只包含页面类型和内容
175 prompt = self.prompt_template_short.format(
176 page_content=page_content,
177 page_type=page_type
178 )
179 logger.debug(f" 使用短 prompt 模式 ({len(prompt)} 字符)")
180 else:
181 # 完整 prompt 模式:包含大纲和用户需求
182 prompt = self.prompt_template.format(
183 page_content=page_content,
184 page_type=page_type,
185 full_outline=full_outline,
186 user_topic=user_topic if user_topic else "未提供"
187 )
188
189 # 调用生成器生成图片。所有路径共用 limiter,避免批量和重试打爆上游。
190 with self.rate_limiter.acquire():
191 if self.provider_config.get('type') == 'google_genai':
192 logger.debug(f" 使用 Google GenAI 生成器")
193 image_data = self.generator.generate_image(
194 prompt=prompt,
195 aspect_ratio=self.provider_config.get('default_aspect_ratio', '3:4'),

Calls 5

_save_imageMethod · 0.95
acquireMethod · 0.80
getMethod · 0.80
merge_generated_imageMethod · 0.80
generate_imageMethod · 0.45