v89-v91 模板增强 + 图源映射 + 多模态提示词可配置化

- 图源映射统一:热点采集与 Pinterest 模式均走 config.product.mark_dirs 配置,按任务序号随机抽模特图/平铺图
- 商品产地固定:统一为「中国大陆」+「产地省份=广东省」(不再读站点/字典映射)
- 模板 SKU 字段检测:按建议售价同一套路检测 SKU分类/SKU数量/SKU数量单位,必填时填入单品/1/件
- 多模态分析提示词可配置:prompts/pinterest_analyze_system.md + user.md,支持国家覆盖,不丢文件回退内置
- 自定义图片模式:新增 pinterest_custom_load_node,图片数量硬校验,选品清单 ≤ 有效图片数
- 模板导出优化:写入前按货号末 3 位升序排序,不再产生空白 xlsx
- 修复 v90 project review 10 项(503 致命终止、线程安全、原子写入等)
This commit is contained in:
2026-08-28 16:24:50 +08:00
parent 2a96ec0870
commit 71a48e4ed5
40 changed files with 780 additions and 200 deletions
+33 -1
View File
@@ -36,11 +36,41 @@ class ThreadSafeErrors:
return len(self._items)
def _mark_fatal_503(state: Dict[str, Any], exc: Exception) -> None:
"""致命图像服务错误(503 / No available compatible accounts)→ 标记提前终止,不静默吞掉。
with_fallback 原本把所有异常都转成一条错误记录并继续,导致致命的 503 被「吞掉」:
路由看不到终止信号,任务会继续做无意义的搜索/分析(重试必然失败)。
检测到致命 503 时同步标记 Pinterest 流水线终止(record_503 + abort_unfinished),
让 _pinterest_route 短路到 pinterest_finalize → template_export(合成模板,保留已完成产品)。
非 Pinterest 节点无流水线对象时,此函数为空操作(不改变原有兜底行为)。
"""
if not _is_fatal_image_error(exc):
return
pipe = state.get("pinterest_pipeline")
if pipe is not None and hasattr(pipe, "record_503") and hasattr(pipe, "abort_unfinished"):
try:
pipe.record_503()
pipe.abort_unfinished()
except Exception: # noqa: BLE001
pass
def _is_fatal_image_error(exc: Exception) -> bool:
"""判断异常是否为致命图像服务错误(503 / 账户不可用)。"""
try:
from graph.pinterest_pipeline import PinterestPipeline
return bool(PinterestPipeline.is_fatal_503(exc))
except Exception: # noqa: BLE001
return False
def with_fallback(node_name: str):
"""装饰器:捕获节点异常,转为 state['errors'] 中的一条记录,返回空更新。
节点内部仍建议自己做精细兜底(降级/默认),with_fallback 是最后一道保险:
任何未预料的异常都不会让整张图中断。
任何未预料的异常都不会让整张图中断。唯一例外——致命图像服务错误(503/账户不可用)
不静默吞掉:会同步标记流水线终止,让任务提前收尾合成模板(见 _mark_fatal_503)。
"""
def deco(fn):
@@ -58,6 +88,8 @@ def with_fallback(node_name: str):
}
errors = list(state.get("errors") or [])
errors.append(err)
# 致命 503:不静默吞掉,标记流水线终止(路由据此短路到收尾合成模板)
_mark_fatal_503(state, e)
# 只更新 errors,其它字段保持上一节点结果,下游继续
return {"errors": errors}