Update form extraction logic in endpoints.py
- 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.
This commit is contained in:
+16
-10
@@ -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"<state>\s*(\d+)\s*</state>", 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 {}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user