From ff060850b17dff535527e2326b1f0a9cb4e08212 Mon Sep 17 00:00:00 2001 From: liu Date: Tue, 23 Apr 2024 09:50:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/supervision/config/ResponseConfig.java | 12 ++++++++++++ .../com/supervision/service/impl/AskServiceImpl.java | 9 ++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/kbqa-common/src/main/java/com/supervision/config/ResponseConfig.java b/kbqa-common/src/main/java/com/supervision/config/ResponseConfig.java index 3628013..b46a8f9 100644 --- a/kbqa-common/src/main/java/com/supervision/config/ResponseConfig.java +++ b/kbqa-common/src/main/java/com/supervision/config/ResponseConfig.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; import com.supervision.domain.GlobalResult; import com.supervision.exception.BusinessException; +import com.supervision.exception.ItemExtractException; import lombok.extern.slf4j.Slf4j; import org.springframework.core.MethodParameter; import org.springframework.http.HttpStatus; @@ -103,6 +104,17 @@ public class ResponseConfig implements ResponseBodyAdvice { return GlobalResult.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), exception.getMessage(), "参数验证异常"); } + /** + * 添加手动校验参数的异常处理 + * @param exception 参数验证异常 + * @return 通用返回值 + */ + @ExceptionHandler(ItemExtractException.class) + public GlobalResult itemExtractExceptionResponse(ItemExtractException exception) { + log.error(exception.getMessage(), exception); + return GlobalResult.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), exception.getMessage(), "您好,我暂时还不会回答这个问题!"); + } + /** * 未知异常处理 * diff --git a/kbqa-graph/src/main/java/com/supervision/service/impl/AskServiceImpl.java b/kbqa-graph/src/main/java/com/supervision/service/impl/AskServiceImpl.java index 40f4674..59ae7e2 100644 --- a/kbqa-graph/src/main/java/com/supervision/service/impl/AskServiceImpl.java +++ b/kbqa-graph/src/main/java/com/supervision/service/impl/AskServiceImpl.java @@ -10,6 +10,7 @@ import com.supervision.enums.EntityQuestionEnum; import com.supervision.enums.IdentifyIntentEnum; import com.supervision.enums.RetireRoleEnum; import com.supervision.exception.BusinessException; +import com.supervision.exception.ItemExtractException; import com.supervision.handler.gpt.AnswerQuestionHandler; import com.supervision.handler.gpt.ConditionJudgeHandler; import com.supervision.handler.gpt.IdentifyIntentHandler; @@ -323,7 +324,13 @@ public class AskServiceImpl implements AskService { throw new BusinessException("暂不支持该意图的问答"); } List allItemNode = findItemNodeHandler.findAllItemNode(); - List extractValue = itemExtractHandler.itemExtractByPossibleItemWithExample(singleTalkReqVO.getUserTalk(), allItemNode); + List extractValue; + try { + extractValue = itemExtractHandler.itemExtractByPossibleItemWithExample(singleTalkReqVO.getUserTalk(), allItemNode); + }catch (ItemExtractException e){ + return SingleTalkResVO.builder().answerText("您好,我暂时还不会回答这个问题哦!").build(); + } + // String extractValue = itemExtractHandler.itemExtractBusiness(singleTalkReqVO.getUserTalk()); // 根据提取的内容,开始在知识图谱中寻找节点(首先找叶子节点,如果叶子节点有数据,直接返回,如果叶子节点没数据,再去找分支节点) List allMatchLeafNode = findItemNodeHandler.findAllMatchLeafNode(extractValue);