refactor(api): TOML 配置 SSOT、统一错误契约、Auth/事务加固与可观测性 (#33)
配置 SSOT(TOML + .env) 统一错误契约 Auth 与事务边界 Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client 可观测性(OpenTelemetry + LGTM)
This commit is contained in:
@@ -6,6 +6,7 @@ from app.core.config import settings
|
||||
from app.core.json_utils import extract_json_payload
|
||||
from app.core.langchain_llm import invoke_json_object
|
||||
from app.core.logging import get_logger
|
||||
from app.features.memoir.constants import memoir
|
||||
|
||||
from .settings import MemoirImageSettings
|
||||
|
||||
@@ -84,7 +85,7 @@ class MemoirImagePromptService:
|
||||
"prompt_context": prompt_context,
|
||||
}
|
||||
except Exception as exc:
|
||||
if settings.image_prompt_fallback_disabled:
|
||||
if memoir.image_prompt_fallback_disabled:
|
||||
raise
|
||||
logger.warning(
|
||||
"图片 prompt 生成回退到默认模板: chapter_category={}, title={}, error={}",
|
||||
@@ -92,7 +93,7 @@ class MemoirImagePromptService:
|
||||
chapter_title,
|
||||
exc,
|
||||
)
|
||||
elif settings.image_prompt_fallback_disabled:
|
||||
elif memoir.image_prompt_fallback_disabled:
|
||||
raise RuntimeError(
|
||||
"MemoirImagePromptService.build_prompt requires LLM when "
|
||||
"image_prompt_fallback_disabled is True"
|
||||
@@ -121,7 +122,7 @@ class MemoirImagePromptService:
|
||||
) -> dict[str, str]:
|
||||
"""生成章节封面图的 image-generation prompt。"""
|
||||
excerpt = (context_excerpt or "").strip()
|
||||
if settings.image_prompt_fallback_disabled and not excerpt:
|
||||
if memoir.image_prompt_fallback_disabled and not excerpt:
|
||||
raise RuntimeError(
|
||||
"Chapter cover prompt requires non-empty context_excerpt when "
|
||||
"image_prompt_fallback_disabled is True"
|
||||
@@ -165,7 +166,7 @@ class MemoirImagePromptService:
|
||||
"prompt_context": prompt_context,
|
||||
}
|
||||
except Exception as exc:
|
||||
if settings.image_prompt_fallback_disabled:
|
||||
if memoir.image_prompt_fallback_disabled:
|
||||
raise
|
||||
logger.warning(
|
||||
"封面 prompt 生成回退到默认模板: chapter_category={}, title={}, error={}",
|
||||
@@ -173,7 +174,7 @@ class MemoirImagePromptService:
|
||||
chapter_title,
|
||||
exc,
|
||||
)
|
||||
elif settings.image_prompt_fallback_disabled:
|
||||
elif memoir.image_prompt_fallback_disabled:
|
||||
raise RuntimeError(
|
||||
"MemoirImagePromptService.build_cover_prompt requires LLM when "
|
||||
"image_prompt_fallback_disabled is True"
|
||||
@@ -208,7 +209,7 @@ class MemoirImagePromptService:
|
||||
from app.agents.stage_constants import STAGE_TO_DEFAULT_CATEGORY
|
||||
|
||||
brief = (prompt_brief or "").strip()
|
||||
if settings.image_prompt_fallback_disabled and not brief:
|
||||
if memoir.image_prompt_fallback_disabled and not brief:
|
||||
raise RuntimeError(
|
||||
"Story image prompt requires non-empty prompt_brief when "
|
||||
"image_prompt_fallback_disabled is True"
|
||||
@@ -258,7 +259,7 @@ class MemoirImagePromptService:
|
||||
"prompt_context": prompt_context,
|
||||
}
|
||||
except Exception as exc:
|
||||
if settings.image_prompt_fallback_disabled:
|
||||
if memoir.image_prompt_fallback_disabled:
|
||||
raise
|
||||
logger.warning(
|
||||
"story 主图 prompt 生成回退到默认模板: stage={}, title={}, error={}",
|
||||
@@ -266,7 +267,7 @@ class MemoirImagePromptService:
|
||||
story_title,
|
||||
exc,
|
||||
)
|
||||
elif settings.image_prompt_fallback_disabled:
|
||||
elif memoir.image_prompt_fallback_disabled:
|
||||
raise RuntimeError(
|
||||
"MemoirImagePromptService.build_story_primary_prompt requires LLM when "
|
||||
"image_prompt_fallback_disabled is True"
|
||||
|
||||
Reference in New Issue
Block a user