KBQA代码提交

main
liu 11 months ago
parent aedab72264
commit 31750e3f0a

@ -5,10 +5,10 @@ import com.supervision.exception.BusinessException;
import com.supervision.service.AskService;
import com.supervision.vo.RoundTalkReqVO;
import com.supervision.vo.RoundTalkResVO;
import com.supervision.vo.UserParamReqVO;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.C;
import org.springframework.web.bind.annotation.*;
@Slf4j
@ -27,4 +27,16 @@ public class AskController {
}
return askService.roundTalk(roundTalkReqVO);
}
@ApiOperation("多轮对话中用户手动填写参数")
@PostMapping("saveUserParam")
public void saveUserParam(@RequestBody UserParamReqVO paramReqVO) {
askService.saveUserParam(paramReqVO);
}
@ApiOperation("查询多轮对话中用户需要填写的参数")
@GetMapping("queryUserNeedParam")
public void queryUserNeedParam(String sessionId) {
}
}

@ -0,0 +1,11 @@
package com.supervision.dto.roundAsk;
import lombok.Data;
@Data
public class UserParamNode {
private String paramType;
private String paramValue;
}

@ -6,9 +6,9 @@ import java.util.ArrayList;
import java.util.List;
public enum IdentifyIntentEnum {
("业务的受理条件", "process_condition", "process_condition_edge", CollUtil.newArrayList("")),
("业务的办理流程", "handler_process", "handler_process_edge", CollUtil.newArrayList("")),
("业务的材料清单", "checklist", "checklist_edge", CollUtil.newArrayList("")),
("业务的受理条件", "process_condition", "process_condition_edge", CollUtil.newArrayList("可不可以XXX", "可以办理XX","能不能够XXX","是否可以XXX","XXX我符合条件吗", "办理XXX满足条件吗")),
("业务的办理流程", "handler_process", "handler_process_edge", CollUtil.newArrayList("办理[]事项的流程是什么样的?")),
("业务的材料清单", "checklist", "checklist_edge", CollUtil.newArrayList("需要提交哪些具体文件或材料?", "如果材料不齐全或不符合要求,将如何处理?")),
("业务的受理范围", "accept_scope", "accept_scope_edge", CollUtil.newArrayList("")),
("业务的办理途径", "handler_channel", "handler_channel_edge", CollUtil.newArrayList("")),
("业务的办理窗口", "handler_place", "handler_place_edge", CollUtil.newArrayList(""));

@ -2,11 +2,13 @@ package com.supervision.handler.gpt;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.supervision.ai.AiUtil;
import com.supervision.ai.dto.MessageDTO;
import com.supervision.enums.IdentifyIntentEnum;
import com.supervision.exception.IdentifyIntentException;
import io.lettuce.core.dynamic.annotation.CommandNaming;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
@ -15,6 +17,7 @@ import java.util.List;
/**
* handler
*/
@Slf4j
@Component
public class IdentifyIntentHandler {
@ -35,9 +38,11 @@ public class IdentifyIntentHandler {
// 构建问题
messageList.add(new MessageDTO("user", "问题是:" + question));
messageList.add(new MessageDTO("assistant", "好的"));
messageList.add(new MessageDTO("user", "现在你可以输出识别到的意图了"));
messageList.add(new MessageDTO("user", "现在你可以根据你学习到的意图列表,来输出根据提供的问题所识别到的意图了"));
log.info("identifyIntent开始识别意图:{}", JSONUtil.toJsonStr(messageList));
// 进行提问
String intent = AiUtil.chatByMessage(messageList);
log.info("identifyIntent意图识别结果为:{}", intent);
// 尝试转为JSON的形式
if (StrUtil.isBlank(intent) || StrUtil.equals("未识别", intent)) {
throw new IdentifyIntentException("意图未识别");

@ -2,9 +2,14 @@ package com.supervision.service;
import com.supervision.vo.RoundTalkReqVO;
import com.supervision.vo.RoundTalkResVO;
import com.supervision.vo.UserParamReqVO;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
public interface AskService {
RoundTalkResVO roundTalk(RoundTalkReqVO roundTalkReqVO);
void saveUserParam(UserParamReqVO paramReqVO);
}

@ -22,6 +22,7 @@ import com.supervision.ngbatis.domain.tag.ItemLeaf;
import com.supervision.service.AskService;
import com.supervision.vo.RoundTalkReqVO;
import com.supervision.vo.RoundTalkResVO;
import com.supervision.vo.UserParamReqVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
@ -55,6 +56,8 @@ public class AskServiceImpl implements AskService {
private static final String SESSION_PARAM = "KBQA:ASK:SESSION_PARAM:";
private static final String USER_PARAM = "KBQA:ASK:USER_PARAM:";
@Override
public RoundTalkResVO roundTalk(RoundTalkReqVO roundTalkReqVO) {
@ -281,4 +284,13 @@ public class AskServiceImpl implements AskService {
}
}
}
@Override
public void saveUserParam(UserParamReqVO paramReqVO) {
// 缓存到Redis中
if (CollUtil.isNotEmpty(paramReqVO.getParamList()) && StrUtil.isNotBlank(paramReqVO.getSessionId())) {
redisTemplate.opsForValue().set(USER_PARAM + paramReqVO.getSessionId(), paramReqVO.getParamList());
}
}
}

@ -0,0 +1,15 @@
package com.supervision.vo;
import com.supervision.dto.roundAsk.UserParamNode;
import lombok.Data;
import java.util.List;
@Data
public class UserParamReqVO {
private String sessionId;
List<UserParamNode> paramList;
}
Loading…
Cancel
Save