修复 Pinterest 分析节点:1) openai 后端兼容 LLM 返回裸数组([...])而非 {designs:[...]},避免 'list' object has no attribute 'get' 崩溃;2) mock 兜底改为真正调用 mock 后端,不再重复调失败的 openai 后端

This commit is contained in:
2026-08-24 15:50:01 +08:00
parent ca567ae198
commit e317547b8b
2 changed files with 13 additions and 4 deletions
+8 -1
View File
@@ -593,7 +593,14 @@ class OpenAICompatBackend(LLMBackend):
print(f"[pinterest_analyze] 解析失败: {e}")
return []
designs = []
for i, d in enumerate(parsed.get("designs") or []):
# 兼容 LLM 返回裸数组([...])或 {designs: [...]} 两种结构
if isinstance(parsed, dict):
designs_raw = parsed.get("designs") or []
elif isinstance(parsed, list):
designs_raw = parsed
else:
designs_raw = []
for i, d in enumerate(designs_raw):
if not isinstance(d, dict):
continue
designs.append({
+5 -3
View File
@@ -104,13 +104,15 @@ def pinterest_analyze_node(state: Dict[str, Any]) -> Dict[str, Any]:
"message": f"term[{term}]: {e}", "trace": ""})
print(f"[pinterest_analyze] 「{term}」分析失败: {e}")
# 3) 兜底:LLM 无结果 → mock 规则简报(零 API 成本,保证有设计可生成)
if not raw_briefs and llm is not None:
# 3) 兜底:LLM 无结果 → mock 规则简报(零 API 成本,保证有设计可生成)
# 注意必须切到 mock 后端,不能再调回失败的 llm(否则同样报错)。
if not raw_briefs:
try:
mock = get_backend("mock")
for term, paths in images.items():
sample = list(paths)[:analyze_per_term]
if sample:
raw_briefs.extend(llm.analyze_pinterest_images(sample, term, country) or [])
raw_briefs.extend(mock.analyze_pinterest_images(sample, term, country) or [])
print(f"[pinterest_analyze] 兜底:mock 规则简报 {len(raw_briefs)}")
except Exception as e: # noqa: BLE001
print(f"[pinterest_analyze] mock 兜底失败: {e}")