提交了新的意图识别提示词

main
liu 10 months ago
parent cddcb8a298
commit 90297ad26a

@ -6,12 +6,12 @@ import java.util.ArrayList;
import java.util.List;
public enum IdentifyIntentEnum {
("业务的受理条件", "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("什么人才能办理XX业务?")),
("业务的办理途径", "handler_channel", "handler_channel_edge", CollUtil.newArrayList("有什么途径可以办理XX业务?","可以线上办理XX吗?","可以线下办理XX吗?")),
("业务的办理窗口", "handler_place", "handler_place_edge", CollUtil.newArrayList("XX的办理窗口在哪里?","线下办理XX去哪里?"));
("业务的受理条件", "process_condition", "process_condition_edge", CollUtil.newArrayList("事项办理的要求或限制,例如,年龄,职业,缴费年限要求等")),
("业务的办理流程", "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("线下办理具体地点,属性包括服务窗口名称,地点、电话、办理时间,位置指引"));
private final String intent;

@ -60,4 +60,41 @@ public class IdentifyIntentHandler {
log.info("未识别,走了默认意图,业务的受理条件");
return IdentifyIntentEnum..getIntent();
}
public String identifyIntentExample(String question) {
String template = "作为一个 AI 助手,你的任务是尝试识别出问题中的意图。现在我给你一些意图以及意图的说明\n" +
"\"\"\"\n" +
"{}"+
"\"\"\"\n" +
"请帮我识别接下来这句话:【{}】可能数据上面的哪种意图请直接给我意图名称例如事项的XXXX。意图范围只在示例中出现的如果未在示例中出现则选择示例中最相近的意图。";
StringBuilder stringBuilder = new StringBuilder();
for (IdentifyIntentEnum value : IdentifyIntentEnum.values()) {
stringBuilder.append("意图是:").append(value.getIntent()).append(";").append("说明是:").append(CollUtil.join(value.getExplainList(), ";")).append("\n");
}
// 首先生成提示词
List<MessageDTO> messageList = new ArrayList<>();
messageList.add(new MessageDTO("user", StrUtil.format(template,stringBuilder.toString(),question)));
log.info("identifyIntent开始识别意图:{}", JSONUtil.toJsonStr(messageList));
// 进行提问
String intent = AiUtil.chatByMessage(messageList);
log.info("identifyIntent意图识别结果为:{}", intent);
// 尝试转为JSON的形式
if (StrUtil.isBlank(intent) || StrUtil.equals("未识别", intent) || intent.contains("未识别")) {
log.info("未识别,走了默认意图,业务的受理条件");
return IdentifyIntentEnum..getIntent();
// 如果没有识别,默认是业务的受理条件
//throw new IdentifyIntentException("意图未识别");
}
for (IdentifyIntentEnum value : IdentifyIntentEnum.values()) {
if (intent.contains(value.getIntent())){
return value.getIntent();
}
}
// throw new IdentifyIntentException("意图未识别");
// 如果没有识别,默认是业务的受理条件
log.info("未识别,走了默认意图,业务的受理条件");
return IdentifyIntentEnum..getIntent();
}
}

@ -12,7 +12,7 @@ import org.springframework.stereotype.Component;
import java.util.*;
/**
* Handler
* Handler
*/
@Slf4j
@Component

@ -84,7 +84,7 @@ public class AskServiceImpl implements AskService {
}
// 判断意图是否为空,如果意图为空,进行识别意图
if (StrUtil.isBlank(sessionParamDTO.getIntent())) {
String intent = identifyIntentHandler.identifyIntent(roundTalkReqVO.getUserTalk());
String intent = identifyIntentHandler.identifyIntentExample(roundTalkReqVO.getUserTalk());
sessionParamDTO.setIntent(intent);
redisTemplate.opsForValue().set(SESSION_PARAM + sessionId, sessionParamDTO);
}
@ -317,7 +317,7 @@ public class AskServiceImpl implements AskService {
@Override
public SingleTalkResVO singleTalk(SingleTalkReqVO singleTalkReqVO) {
// 单轮对话,直接根据用户的问题去找意图
String intent = identifyIntentHandler.identifyIntent(singleTalkReqVO.getUserTalk());
String intent = identifyIntentHandler.identifyIntentExample(singleTalkReqVO.getUserTalk());
// 根据用户的意图找到对应的节点
IdentifyIntentEnum intentEnum = IdentifyIntentEnum.getEnumByIntent(intent);
if (ObjectUtil.isEmpty(intentEnum) || null == intentEnum) {

Loading…
Cancel
Save