Skip to content

Commit 41f77a5

Browse files
optimize
1 parent a4005c3 commit 41f77a5

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

apps/application/flow/step_node/intent_node/impl/base_intent_node.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,14 @@ def get_branch_by_id(category_id: int):
189189
return None
190190

191191
try:
192-
result_json = json.loads(result)
193-
classification_id = result_json.get('classificationId')
192+
# 先尝试解析为数字(自定义提示词模板时,可提示大模型只输出ID值)
193+
classification_id = self.to_int(result)
194+
195+
# 再尝试解析为 JSON
196+
if classification_id is None:
197+
result_json = json.loads(result)
198+
classification_id = result_json.get('classificationId')
199+
194200
# 如果是 0 ,返回其他分支
195201
matched_branch = get_branch_by_id(classification_id)
196202
if matched_branch:
@@ -230,6 +236,12 @@ def parse_result_reason(self, result: str):
230236

231237
return ''
232238

239+
def to_int(self, str):
240+
try:
241+
return int(str)
242+
except ValueError:
243+
return None
244+
233245
def find_other_branch(self, branch: List[Dict]) -> Dict[str, Any] | None:
234246
"""查找其他分支"""
235247
for b in branch:

0 commit comments

Comments
 (0)