Просмотр исходного кода

add json check after strategy generation

guantao 1 месяц назад
Родитель
Сommit
41eee5b2ca
2 измененных файлов с 73 добавлено и 0 удалено
  1. 53 0
      examples/process_pipeline/run_metrics.json
  2. 20 0
      examples/process_pipeline/run_pipeline.py

+ 53 - 0
examples/process_pipeline/run_metrics.json

@@ -1092,5 +1092,58 @@
     },
     },
     "errors": [],
     "errors": [],
     "timestamp": "2026-04-21T11:08:42.407784"
     "timestamp": "2026-04-21T11:08:42.407784"
+  },
+  {
+    "index": 31,
+    "requirement": "给普通猫咪照片套上不同职业的服装和场景(如医生、上班族、老板等),并保持猫咪面部表情清晰可辨,制作出系列表情包拼贴图...",
+    "duration_seconds": 0.0,
+    "total_cost_usd": 0.0,
+    "costs_breakdown": {},
+    "errors": [],
+    "timestamp": "2026-04-21T19:07:45.850925"
+  },
+  {
+    "index": 31,
+    "requirement": "给普通猫咪照片套上不同职业的服装和场景(如医生、上班族、老板等),并保持猫咪面部表情清晰可辨,制作出系列表情包拼贴图...",
+    "duration_seconds": 716.04,
+    "total_cost_usd": 0.9084,
+    "costs_breakdown": {
+      "P3_Assembler": 0.9084
+    },
+    "errors": [],
+    "timestamp": "2026-04-21T19:20:35.970816"
+  },
+  {
+    "index": 84,
+    "requirement": "生成具有统一色调风格的插画场景,整体画面使用高度协调的单一色系(如全蓝紫色调的火车风景、全粉紫色调的奇幻海洋),让画面中所有元素的颜色都偏向同一个色相,营造出梦...",
+    "duration_seconds": 622.88,
+    "total_cost_usd": 0.6898,
+    "costs_breakdown": {
+      "P3_Assembler": 0.6898
+    },
+    "errors": [],
+    "timestamp": "2026-04-21T19:21:25.669206"
+  },
+  {
+    "index": 68,
+    "requirement": "制作融合插画风格的信息图文海报:以卡通机器人/科技感插图作为视觉主体,搭配醒目的彩色标题文字和数据图表,整体呈现出活泼又专业的视觉效果...",
+    "duration_seconds": 887.07,
+    "total_cost_usd": 1.2375,
+    "costs_breakdown": {
+      "P3_Assembler": 1.2375
+    },
+    "errors": [],
+    "timestamp": "2026-04-21T19:24:50.708365"
+  },
+  {
+    "index": 45,
+    "requirement": "制作图文卡片式科普内容:每张卡片包含统一的标题样式、编号序列、配套插图(卡通/示意图风格)和说明文字,多张卡片拼成一组,整体风格统一、排版清晰,适合健康养生、步...",
+    "duration_seconds": 872.16,
+    "total_cost_usd": 1.1204,
+    "costs_breakdown": {
+      "P3_Assembler": 1.1204
+    },
+    "errors": [],
+    "timestamp": "2026-04-21T19:47:27.018090"
   }
   }
 ]
 ]

+ 20 - 0
examples/process_pipeline/run_pipeline.py

@@ -115,6 +115,16 @@ async def run_agent_task(runner: AgentRunner, prompt_name: str, kwargs: dict, ta
             err_msg = f"{type(e).__name__}: {e}"
             err_msg = f"{type(e).__name__}: {e}"
             print(f"❌ [Exception Recovery] {task_name} crashed: {err_msg}")
             print(f"❌ [Exception Recovery] {task_name} crashed: {err_msg}")
             task_errors.append(f"{task_name} recovery crashed: {err_msg}")
             task_errors.append(f"{task_name} recovery crashed: {err_msg}")
+            
+    if out_file and Path(out_file).exists() and str(out_file).endswith(".json"):
+        try:
+            with open(out_file, "r", encoding="utf-8") as f:
+                json.loads(f.read())
+            print(f"   ✅ [JSON Validated] {Path(out_file).name}")
+        except json.JSONDecodeError as e:
+            err_msg = f"Invalid JSON syntax in {Path(out_file).name}: {e}"
+            print(f"❌ [Validation Error] {task_name}: {err_msg}")
+            task_errors.append(f"{task_name} JSON Error: {e}")
                     
                     
     return task_cost, task_errors
     return task_cost, task_errors
 
 
@@ -266,6 +276,16 @@ async def run_anthropic_sdk_task(prompt_name: str, kwargs: dict, task_name: str,
             print(f"❌ [Fail SDK Recovery] {task_name}: {e}")
             print(f"❌ [Fail SDK Recovery] {task_name}: {e}")
             task_errors.append(str(e))
             task_errors.append(str(e))
             
             
+    if out_file and Path(out_file).exists() and str(out_file).endswith(".json"):
+        try:
+            with open(out_file, "r", encoding="utf-8") as f:
+                json.loads(f.read())
+            print(f"   ✅ [JSON Validated] {Path(out_file).name}")
+        except json.JSONDecodeError as e:
+            err_msg = f"Invalid JSON syntax in {Path(out_file).name}: {e}"
+            print(f"❌ [Validation Error] {task_name}: {err_msg}")
+            task_errors.append(f"{task_name} JSON Error: {e}")
+            
     return task_cost, task_errors
     return task_cost, task_errors
 
 
 async def main():
 async def main():