From e261e979165a187dc6aa52f333e7085945244cee Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Tue, 11 Aug 2026 14:58:47 +0800 Subject: [PATCH] Update form extraction logic in endpoints.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Changed the module name for form extraction to "更新表单" for clarity. - Enhanced the extraction process to accommodate various output formats from nodes, ensuring compatibility with different structures. - Improved handling of empty or invalid form updates, returning an empty object when necessary to maintain robustness. --- src/api/endpoints.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/api/endpoints.py b/src/api/endpoints.py index 77ab10f..c6481ac 100644 --- a/src/api/endpoints.py +++ b/src/api/endpoints.py @@ -14,7 +14,8 @@ import re import time router = APIRouter() -FORM_EXTRACT_MODULE_NAME = "文本内容提取事故信息" +# FORM_EXTRACT_MODULE_NAME = "文本内容提取事故信息" +FORM_EXTRACT_MODULE_NAME = "更新表单" STATE_TAG_PATTERN = re.compile(r"\s*(\d+)\s*", flags=re.DOTALL) STATUS_CODE_MAP = { '0000': '结束通话', @@ -87,22 +88,27 @@ def extract_form_update_from_flow_nodes(nodes): """Extract form update data from the configured FastGPT content-extract node.""" if not isinstance(nodes, list): return {} - for node in nodes: if not isinstance(node, dict): continue if node.get("moduleName") != FORM_EXTRACT_MODULE_NAME: continue - - extract_result = node.get("extractResult", {}) - if not isinstance(extract_result, dict): + # 代码节点返回值在 customOutputs;兼容旧版/其他形态 + outputs = node.get("customOutputs") + if not isinstance(outputs, dict): + outputs = node.get("nodeOutputs") + if not isinstance(outputs, dict): + outputs = node.get("extractResult") + if not isinstance(outputs, dict): return {} - - form_update = extract_result.get("formUpdate", "") - if not form_update: + form_update = outputs.get("formUpdate", "") + if form_update in ("", None): return {} - return parse_json_value(form_update) - + parsed = parse_json_value(form_update) + # 无变更时代码节点常返回 {},直接透传空对象 + if not isinstance(parsed, dict): + return {} + return parsed return {}