feat: 生成图片提示词agent结构封装
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
Agent 模块(按功能拆分:chat / memoir)
|
||||
Agent 模块(按功能拆分:chat / memoir / image_prompt)
|
||||
"""
|
||||
from app.agents.chat import (
|
||||
ChatOrchestrator,
|
||||
@@ -7,6 +7,7 @@ from app.agents.chat import (
|
||||
InterviewAgent,
|
||||
ProfileAgent,
|
||||
)
|
||||
from app.agents.image_prompt import ImagePromptOrchestrator, PromptGenerationAgent
|
||||
from app.agents.memoir import BackgroundTaskRunner, MemoryAgent
|
||||
|
||||
__all__ = [
|
||||
@@ -16,4 +17,6 @@ __all__ = [
|
||||
"ProfileAgent",
|
||||
"InterviewAgent",
|
||||
"BackgroundTaskRunner",
|
||||
"ImagePromptOrchestrator",
|
||||
"PromptGenerationAgent",
|
||||
]
|
||||
|
||||
8
api/app/agents/image_prompt/__init__.py
Normal file
8
api/app/agents/image_prompt/__init__.py
Normal file
@@ -0,0 +1,8 @@
|
||||
"""图片提示词模块:ImagePromptOrchestrator + PromptGenerationAgent"""
|
||||
from app.agents.image_prompt.orchestrator import ImagePromptOrchestrator
|
||||
from app.agents.image_prompt.prompt_agent import PromptGenerationAgent
|
||||
|
||||
__all__ = [
|
||||
"ImagePromptOrchestrator",
|
||||
"PromptGenerationAgent",
|
||||
]
|
||||
57
api/app/agents/image_prompt/orchestrator.py
Normal file
57
api/app/agents/image_prompt/orchestrator.py
Normal file
@@ -0,0 +1,57 @@
|
||||
"""
|
||||
ImagePromptOrchestrator:图片提示词生成编排器。
|
||||
根据调用方(封面/正文)选择 build_prompt 或 build_cover_prompt;
|
||||
统一异常处理和回退;内部委托 PromptGenerationAgent。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Optional
|
||||
|
||||
from app.features.memoir.memoir_images.settings import MemoirImageSettings
|
||||
|
||||
from app.agents.image_prompt.prompt_agent import PromptGenerationAgent
|
||||
|
||||
|
||||
class ImagePromptOrchestrator:
|
||||
"""
|
||||
图片提示词编排器。
|
||||
区分封面 vs 正文配图,统一调用 PromptGenerationAgent;
|
||||
异常与回退由 PromptGenerationAgent(底层 MemoirImagePromptService)处理。
|
||||
"""
|
||||
|
||||
def __init__(self, llm: Optional[Any], settings: MemoirImageSettings) -> None:
|
||||
self._agent = PromptGenerationAgent(llm=llm, settings=settings)
|
||||
|
||||
def build_prompt(
|
||||
self,
|
||||
chapter_title: str,
|
||||
chapter_category: str,
|
||||
description: str,
|
||||
context_excerpt: str,
|
||||
) -> dict[str, str]:
|
||||
"""
|
||||
生成正文配图的 prompt。
|
||||
委托 PromptGenerationAgent,已含 LLM 调用失败时的 fallback 逻辑。
|
||||
"""
|
||||
return self._agent.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]:
|
||||
"""
|
||||
生成章节封面的 prompt。
|
||||
委托 PromptGenerationAgent,已含 LLM 调用失败时的 fallback 逻辑。
|
||||
"""
|
||||
return self._agent.build_cover_prompt(
|
||||
chapter_title=chapter_title,
|
||||
chapter_category=chapter_category,
|
||||
context_excerpt=context_excerpt,
|
||||
)
|
||||
50
api/app/agents/image_prompt/prompt_agent.py
Normal file
50
api/app/agents/image_prompt/prompt_agent.py
Normal file
@@ -0,0 +1,50 @@
|
||||
"""
|
||||
PromptGenerationAgent:生成回忆录配图的 image-generation prompt。
|
||||
接收 chapter_title、chapter_category、description、context_excerpt,
|
||||
调用 LLM 或 fallback 生成 {prompt, style, size}。
|
||||
底层委托 MemoirImagePromptService,保持对外接口兼容。
|
||||
"""
|
||||
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,
|
||||
)
|
||||
Reference in New Issue
Block a user