Files
pod_trend_agent/graph/state.py
T
3218485270 3dc594cf57 v92-v105 多国适配 + 模板导出增强 + 生图可靠性优化
- 新增韩国(KR)适配:countries/pinterest 种子词、K-pop 提示词、UI 国家列表
- 爬虫跨运行持久化已采集 URL(.collected_urls.json),同关键词重复搜索采新图
- 模板导出增强:SPU 商品属性列名前缀剥离匹配、尺码下拉框 INDIRECT 动态引用、
  SPU 字段映射(袖长/门襟/胸垫等)、季节/印花图案女装映射、建议售价统一必填、
  SKU 分类/数量/单位直接填默认值
- 自定义模式:多模态提示词独立(custom_analyze_*)、生图提示词模板可配置
- Pinterest:空选品守卫、连续空分析保护(max_empty_analyze)、flat_prompt 配置覆盖
- 生图可靠性:开始/完成进度日志、异步任务轮询超时 60s→300s
2026-08-31 18:35:51 +08:00

48 lines
3.7 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.
"""LangGraph 共享状态定义。
所有节点都读写 AgentState。键全部 optionaltotal=False),
因此单个节点崩溃 / 返回空时不会破坏整图,下游可用上一节点的残余数据继续。
"""
from typing import TypedDict, List, Dict, Any, Optional
class AgentState(TypedDict, total=False):
# —— 路由 / 配置 ——
country: str # 当前处理的国家代码(US/GB/JP/AU
config: Dict[str, Any] # 全局配置(config.yaml
country_config: Dict[str, Any] # 该国合并后的配置(全局 + configs/countries/*.yaml + prompts/<country>/aesthetics.yaml
prompts_dir: str # prompts/<country> 绝对路径
output_dir: str # output/<country> 绝对路径
cache_dir: str # output/<country> 根目录(采集缓存/去重/简报缓存)
task_timestamp: str # 任务开始时间戳(OSS 路径段 / 产物文件夹名)
oss_seq: int # 货号计数(000 起,最多 999)
base_image: str # 平铺衣服底图路径(可选,印图用)
# —— 流水线数据(逐节点累积)——
raw_rows: List[Dict[str, Any]] # fetch 产出:各源原始行(统一格式)
filtered_rows: List[Dict[str, Any]] # filter 产出:去黑名单/人名/泛词后
scored_rows: List[Dict[str, Any]] # score 产出:归一化 + 融合 + 综合分
screened: List[Dict[str, Any]] # screen 产出:合规风险 + 结构化四要素
briefs: List[Dict[str, Any]] # prompt_build 产出:含最终 image/wearable/composite 提示词
composite: List[Dict[str, Any]] # compose 产出:封装提示词包(= briefs 子集,便于下游印图)
designs: List[Dict[str, Any]] # compose 产出:纯印花设计稿 [{topic, path}]product 用它做图2
product: List[Dict[str, Any]] # product 产出:产品图生成(SPU/SKU/底图/印花/模特合成)
seed_words: Dict[str, Any] # seed 产出:动态种子词(含 llm_style_seeds / llm_related_seeds
# —— Pinterest 参考模式(独立于 Google Trends 采集链路)——
pinterest_search_terms: List[str] # pinterest_search 产出:LLM 生成的搜索词
pinterest_images: Dict[str, List[str]] # pinterest_scrape 产出:搜索词 → 爬取图片路径列表
pinterest_briefs: List[Dict[str, Any]] # pinterest_analyze 产出:LLM 分析图片的原始设计简报
pinterest_login: Dict[str, Any] # pinterest_scrape 产出:登录态检测结果 {status, detail, ...}
# —— Pinterest 按需搜索循环状态 ——
pinterest_target: int # 目标简报数(= spu_tasks 数量,每款一个设计)
pinterest_rounds: int # 已搜索轮次
pinterest_empty_rounds: int # 连续图片分析无新增简报的轮数(防"逐一取下一张参考图"空转)
pinterest_attempted: List[str] # 本轮已尝试(未持久化)的搜索词,防同轮重复
pinterest_pipeline: Any # PinterestPipeline 实例(简报池 + 并发生成线程)
# —— 可观测性 ——
errors: List[Dict[str, Any]] # 各节点兜底捕获的错误:{node, type, message, trace}
stats: Dict[str, Any] # 各阶段统计:{fetch, filter, score, screen, prompt, compose}