2026-03-19 10:43:34 +08:00
|
|
|
|
"""
|
|
|
|
|
|
PromptGenerationAgent:生成回忆录配图的 image-generation prompt。
|
|
|
|
|
|
接收 chapter_title、chapter_category、description、context_excerpt,
|
|
|
|
|
|
调用 LLM 或 fallback 生成 {prompt, style, size}。
|
2026-03-22 16:45:57 +08:00
|
|
|
|
底层委托 MemoirImagePromptService。
|
2026-03-19 10:43:34 +08:00
|
|
|
|
"""
|
2026-03-19 14:36:14 +08:00
|
|
|
|
|
2026-03-19 10:43:34 +08:00
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
|
|
from typing import Any, Optional
|
|
|
|
|
|
|
|
|
|
|
|
from app.features.memoir.memoir_images.prompting import MemoirImagePromptService
|
|
|
|
|
|
from app.features.memoir.memoir_images.settings import MemoirImageSettings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PromptGenerationAgent:
|
|
|
|
|
|
"""
|
|
|
|
|
|
图片提示词生成 Specialist Agent。
|
|
|
|
|
|
封装 MemoirImagePromptService,提供 build_prompt / build_cover_prompt 接口。
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, llm: Optional[Any], settings: MemoirImageSettings) -> None:
|
|
|
|
|
|
self._service = MemoirImagePromptService(llm=llm, settings=settings)
|
|
|
|
|
|
|
|
|
|
|
|
def build_prompt(
|
|
|
|
|
|
self,
|
|
|
|
|
|
chapter_title: str,
|
|
|
|
|
|
chapter_category: str,
|
|
|
|
|
|
description: str,
|
|
|
|
|
|
context_excerpt: str,
|
|
|
|
|
|
) -> dict[str, str]:
|
|
|
|
|
|
"""生成正文配图的 image-generation prompt。"""
|
|
|
|
|
|
return self._service.build_prompt(
|
|
|
|
|
|
chapter_title=chapter_title,
|
|
|
|
|
|
chapter_category=chapter_category,
|
|
|
|
|
|
description=description,
|
|
|
|
|
|
context_excerpt=context_excerpt,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def build_cover_prompt(
|
|
|
|
|
|
self,
|
|
|
|
|
|
chapter_title: str,
|
|
|
|
|
|
chapter_category: str,
|
|
|
|
|
|
context_excerpt: str,
|
|
|
|
|
|
) -> dict[str, str]:
|
|
|
|
|
|
"""生成章节封面图的 image-generation prompt。"""
|
|
|
|
|
|
return self._service.build_cover_prompt(
|
|
|
|
|
|
chapter_title=chapter_title,
|
|
|
|
|
|
chapter_category=chapter_category,
|
|
|
|
|
|
context_excerpt=context_excerpt,
|
|
|
|
|
|
)
|
2026-04-02 12:00:00 +08:00
|
|
|
|
|
|
|
|
|
|
def build_story_primary_prompt(
|
|
|
|
|
|
self,
|
|
|
|
|
|
story_title: str,
|
|
|
|
|
|
story_stage: str | None,
|
|
|
|
|
|
prompt_brief: str,
|
|
|
|
|
|
style_profile: str | None,
|
|
|
|
|
|
) -> dict[str, str]:
|
|
|
|
|
|
"""生成 story 主插图的 image-generation prompt。"""
|
|
|
|
|
|
return self._service.build_story_primary_prompt(
|
|
|
|
|
|
story_title=story_title,
|
|
|
|
|
|
story_stage=story_stage,
|
|
|
|
|
|
prompt_brief=prompt_brief,
|
|
|
|
|
|
style_profile=style_profile,
|
|
|
|
|
|
)
|