Files
life-echo/api/app/agents/image_prompt/orchestrator.py

58 lines
1.8 KiB
Python
Raw Normal View History

"""
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,
)