Showing
1 changed file
with
21 additions
and
1 deletions
| @@ -18,6 +18,7 @@ from flask import Blueprint, request, jsonify, Response, send_file, stream_with_ | @@ -18,6 +18,7 @@ from flask import Blueprint, request, jsonify, Response, send_file, stream_with_ | ||
| 18 | from typing import Dict, Any, List, Optional | 18 | from typing import Dict, Any, List, Optional |
| 19 | from loguru import logger | 19 | from loguru import logger |
| 20 | from .agent import ReportAgent, create_agent | 20 | from .agent import ReportAgent, create_agent |
| 21 | +from .nodes import ChapterJsonParseError | ||
| 21 | from .utils.config import settings | 22 | from .utils.config import settings |
| 22 | 23 | ||
| 23 | 24 | ||
| @@ -185,7 +186,7 @@ class ReportTask: | @@ -185,7 +186,7 @@ class ReportTask: | ||
| 185 | self.task_id = task_id | 186 | self.task_id = task_id |
| 186 | self.query = query | 187 | self.query = query |
| 187 | self.custom_template = custom_template | 188 | self.custom_template = custom_template |
| 188 | - self.status = "pending" # pending, running, completed, error | 189 | + self.status = "pending" # 四种状态(pending/running/completed/error) |
| 189 | self.progress = 0 | 190 | self.progress = 0 |
| 190 | self.result = None | 191 | self.result = None |
| 191 | self.error_message = "" | 192 | self.error_message = "" |
| @@ -377,6 +378,25 @@ def run_report_generation(task: ReportTask, query: str, custom_template: str = " | @@ -377,6 +378,25 @@ def run_report_generation(task: ReportTask, query: str, custom_template: str = " | ||
| 377 | stream_handler=stream_handler | 378 | stream_handler=stream_handler |
| 378 | ) | 379 | ) |
| 379 | break | 380 | break |
| 381 | + except ChapterJsonParseError as err: | ||
| 382 | + hint_message = "尝试将Report Engine的API更换为算力更强、上下文更长的LLM" | ||
| 383 | + task.publish_event('warning', { | ||
| 384 | + 'message': hint_message, | ||
| 385 | + 'stage': 'agent_running', | ||
| 386 | + 'attempt': attempt, | ||
| 387 | + 'reason': 'chapter_json_parse', | ||
| 388 | + 'error': str(err), | ||
| 389 | + 'task': task.to_dict(), | ||
| 390 | + }) | ||
| 391 | + # 旧逻辑:在JSON解析失败后重启Report Engine | ||
| 392 | + # backoff = min(5 * attempt, 15) | ||
| 393 | + # task.publish_event('stage', { | ||
| 394 | + # 'message': f'{backoff} 秒后重试生成任务', | ||
| 395 | + # 'stage': 'retry_wait', | ||
| 396 | + # 'wait_seconds': backoff | ||
| 397 | + # }) | ||
| 398 | + # time.sleep(backoff) | ||
| 399 | + raise ChapterJsonParseError(hint_message) from err | ||
| 380 | except Exception as err: | 400 | except Exception as err: |
| 381 | # 将错误即时推送至前端,方便观察重试策略 | 401 | # 将错误即时推送至前端,方便观察重试策略 |
| 382 | task.publish_event('warning', { | 402 | task.publish_event('warning', { |
-
Please register or login to post a comment