|
|
|
@ -20,10 +20,7 @@ import com.supervision.handler.graph.FindItemNodeHandler;
|
|
|
|
|
import com.supervision.ngbatis.domain.tag.Condition;
|
|
|
|
|
import com.supervision.ngbatis.domain.tag.ItemLeaf;
|
|
|
|
|
import com.supervision.service.AskService;
|
|
|
|
|
import com.supervision.vo.RoleSetResVO;
|
|
|
|
|
import com.supervision.vo.RoundTalkReqVO;
|
|
|
|
|
import com.supervision.vo.RoundTalkResVO;
|
|
|
|
|
import com.supervision.vo.RoleSetReqVO;
|
|
|
|
|
import com.supervision.vo.*;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
@ -196,26 +193,25 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
// 根据意图和节点,找到对应的结果
|
|
|
|
|
List<String> itemDetail = findItemDetailHandler.findItemDetail(matchItemLeaf.getVid(), intentEnum.getTagType(), intentEnum.getEdgeType());
|
|
|
|
|
if (CollUtil.isEmpty(itemDetail)) {
|
|
|
|
|
return RoundTalkResVO.builder().sessionId(sessionParamDTO.getSessionId()).replyQuestion("暂不支持该意图的问答").build();
|
|
|
|
|
return RoundTalkResVO.builder().sessionId(sessionParamDTO.getSessionId()).answerText("暂时还不会回答这个问题哦").build();
|
|
|
|
|
}
|
|
|
|
|
// 提交GPT,问问题的答案
|
|
|
|
|
String answer = answerQuestionHandler.answerQuestion(sessionParamDTO.getOriginalQuestion(), itemDetail, sessionParamDTO.getTalkRecord());
|
|
|
|
|
if (StrUtil.isBlank(answer)) {
|
|
|
|
|
return RoundTalkResVO.builder().sessionId(sessionParamDTO.getSessionId()).replyQuestion("暂时还不会回答这个问题哦").build();
|
|
|
|
|
return RoundTalkResVO.builder().sessionId(sessionParamDTO.getSessionId()).answerText("暂时还不会回答这个问题哦!").build();
|
|
|
|
|
}
|
|
|
|
|
// 清空问话实体
|
|
|
|
|
sessionParamDTO.setCurrentEntity(null);
|
|
|
|
|
redisTemplate.opsForValue().set(SESSION_PARAM + sessionParamDTO.getSessionId(), sessionParamDTO);
|
|
|
|
|
return RoundTalkResVO.builder().sessionId(sessionParamDTO.getSessionId()).replyQuestion(answer).build();
|
|
|
|
|
return RoundTalkResVO.builder().sessionId(sessionParamDTO.getSessionId()).answerText(answer).build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void filterPath(SessionParamDTO sessionParamDTO, String userTalk) {
|
|
|
|
|
// 遍历所有的path,找到回答
|
|
|
|
|
Set<String> possibleAnswerSet = findPossibleAnswerSet(sessionParamDTO);
|
|
|
|
|
Set<String> judgeResultSet = conditionJudgeHandler.newConditionJudge(sessionParamDTO.getCurrentEntity().getCurrentQuestion(),
|
|
|
|
|
Set<String> judgeResultSet = conditionJudgeHandler.conditionJudgeAll(sessionParamDTO.getCurrentEntity().getCurrentQuestion(),
|
|
|
|
|
possibleAnswerSet,
|
|
|
|
|
userTalk,
|
|
|
|
|
sessionParamDTO.getCurrentEntity().getCurrentEntityType());
|
|
|
|
|
userTalk);
|
|
|
|
|
// 筛选路径,如果某个路径的结果不在比较结果中,说明这个结果不对,排除这个路径
|
|
|
|
|
pathFilterByJudgeResult(sessionParamDTO.getCurrentEntity().getCurrentEntityType(), judgeResultSet, sessionParamDTO);
|
|
|
|
|
filterNotMatchNode(sessionParamDTO);
|
|
|
|
@ -317,6 +313,44 @@ public class AskServiceImpl implements AskService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public SingleTalkResVO singleTalk(SingleTalkReqVO singleTalkReqVO) {
|
|
|
|
|
// 单轮对话,直接根据用户的问题去找意图
|
|
|
|
|
String intent = identifyIntentHandler.identifyIntent(singleTalkReqVO.getUserTalk());
|
|
|
|
|
// 提供用户问题中的业务
|
|
|
|
|
String extractValue = itemExtractHandler.itemExtractBusiness(singleTalkReqVO.getUserTalk());
|
|
|
|
|
// 根据提取的内容,开始在知识图谱中寻找节点(首先找叶子节点,如果叶子节点有数据,直接返回,如果叶子节点没数据,再去找分支节点)
|
|
|
|
|
List<ItemLeaf> allMatchLeafNode = findItemNodeHandler.findAllMatchLeafNode(Collections.singletonList(extractValue));
|
|
|
|
|
// 然后根据叶子节点,还有意图,去找到所有的对应数据
|
|
|
|
|
// 根据用户的意图找到对应的节点
|
|
|
|
|
IdentifyIntentEnum intentEnum = IdentifyIntentEnum.getEnumByIntent(intent);
|
|
|
|
|
if (ObjectUtil.isEmpty(intentEnum) || null == intentEnum) {
|
|
|
|
|
throw new BusinessException("暂不支持该意图的问答");
|
|
|
|
|
}
|
|
|
|
|
Map<String, List<String>> detailMap = new HashMap<>();
|
|
|
|
|
for (ItemLeaf itemLeaf : allMatchLeafNode) {
|
|
|
|
|
try {
|
|
|
|
|
// 根据意图和节点,找到对应的结果
|
|
|
|
|
List<String> itemDetailList = findItemDetailHandler.findItemDetail(itemLeaf.getVid(), intentEnum.getTagType(), intentEnum.getEdgeType());
|
|
|
|
|
if (CollUtil.isNotEmpty(itemDetailList)) {
|
|
|
|
|
detailMap.put(itemLeaf.getItemName(), itemDetailList);
|
|
|
|
|
}
|
|
|
|
|
} catch (BusinessException e) {
|
|
|
|
|
log.info("未找到对应节点,忽略");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (CollUtil.isEmpty(detailMap)) {
|
|
|
|
|
return SingleTalkResVO.builder().answerText("暂时还不会回答这个问题哦!").build();
|
|
|
|
|
}
|
|
|
|
|
// 提交GPT,问问题的答案
|
|
|
|
|
String answer = answerQuestionHandler.answerSingleQuestion(singleTalkReqVO.getUserTalk(), detailMap);
|
|
|
|
|
if (StrUtil.isBlank(answer)) {
|
|
|
|
|
return SingleTalkResVO.builder().answerText("暂时还不会回答这个问题哦!").build();
|
|
|
|
|
}
|
|
|
|
|
return SingleTalkResVO.builder().answerText(answer).build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RoundTalkResVO saveUserParam(RoleSetReqVO paramReqVO) {
|
|
|
|
|
// 缓存到Redis中
|
|
|
|
|