Files
life-echo/api/app/agents/image_prompt/orchestrator.py
Kevin 309a051038 feat: 回忆录证据血缘与内部评测可追溯,顺带对齐本地评测台与 CI
数据库与模型:新增多版迁移(章节证据快照、对话血缘、记忆事实/时间线 lineage 等),把「成稿 ↔ 对话/记忆」的溯源信息落到表结构里。
业务链路:会话与 WS、回忆录/故事流水线、记忆写入与 enrichment 等跟着接上线索与快照;新增章节证据快照与评测侧 EvalTraceService 等模块,方便组评审用的证据包。
内部评测:自动化 run 与手工 memoir 评审共用可追溯证据;rubric/ judge 相关脚本与文档有配套调整。
app-eval-web:Memoir/实验详情里能展开看证据摘要与 evidence_trace(含对话轮次 id);Vite 代理与 development.sh 注入的 API 端口与当前默认内部评测端口一致,避免改端口后页面连错服务。
工程杂项:GitHub Actions / 仓库说明有更新;各适配器与支付/配额/plan 等多处为小改动或跟随主改动的收尾;新增/扩充了?
2026-04-08 15:37:09 +08:00

81 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
ImagePromptOrchestrator图片提示词生成编排器。
根据调用方(封面/正文)选择 build_prompt 或 build_cover_prompt
统一异常处理和回退;内部委托 PromptGenerationAgent。
"""
from __future__ import annotations
from typing import Any, Optional
from app.agents.image_prompt.prompt_agent import PromptGenerationAgent
from app.features.memoir.memoir_images.settings import MemoirImageSettings
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,
)
def build_story_primary_prompt(
self,
story_title: str,
story_stage: str | None,
prompt_brief: str,
style_profile: str | None,
) -> dict[str, str]:
"""生成 story 主插图的 prompt。"""
return self._agent.build_story_primary_prompt(
story_title=story_title,
story_stage=story_stage,
prompt_brief=prompt_brief,
style_profile=style_profile,
)
def get_image_prompt_orchestrator() -> ImagePromptOrchestrator:
"""Celery / 后台任务入口:统一装配 LLM 与 MemoirImageSettings。"""
from app.core.dependencies import get_llm_provider
llm = getattr(get_llm_provider(), "langchain_llm", None)
return ImagePromptOrchestrator(llm=llm, settings=MemoirImageSettings.from_env())