|
|
|
@ -25,6 +25,7 @@ import com.supervision.police.service.*;
|
|
|
|
|
import com.supervision.police.vo.ChatReqVO;
|
|
|
|
|
import com.supervision.police.vo.ChatResVO;
|
|
|
|
|
import com.supervision.police.vo.ConversationResVo;
|
|
|
|
|
import com.supervision.police.vo.dify.DIFYChatReqInputVO;
|
|
|
|
|
import com.supervision.police.vo.dify.DifyChatReqVO;
|
|
|
|
|
import com.supervision.police.vo.dify.DifyChatResVO;
|
|
|
|
|
import com.supervision.police.vo.dify.KnowledgeBaseSegmentVO;
|
|
|
|
@ -122,7 +123,7 @@ public class ChatServiceImpl implements ChatService {
|
|
|
|
|
type = QA_TYPE_NX_LLM;
|
|
|
|
|
intentType = INTENT_TYPE_INDEX_RESULT;
|
|
|
|
|
handleIndexResultQA(modelIndices, query, caseId, answerMap);
|
|
|
|
|
} else if (INTENT_TYPE_TEXT_CASE_RESULT.equals(query) || INTENT_TYPE_CASE_RESULT.equals(intentType)) {
|
|
|
|
|
} else if (INTENT_TYPE_TEXT_CASE_RESULT.equals(query)) {
|
|
|
|
|
type = QA_TYPE_NX_LLM;
|
|
|
|
|
intentType = INTENT_TYPE_CASE_RESULT;
|
|
|
|
|
ModelCase modelCase = modelCaseService.getById(caseId);
|
|
|
|
@ -133,11 +134,11 @@ public class ChatServiceImpl implements ChatService {
|
|
|
|
|
modelService.analyseCase(analyseCaseDTO);
|
|
|
|
|
}
|
|
|
|
|
answerMap = JSON.parseObject(JSON.toJSONString(modelService.caseScoreDetail(caseId)), Map.class);
|
|
|
|
|
} else if (INTENT_TYPE_TEXT_CASE_OVERVIEW.equals(query) || INTENT_TYPE_CASE_OVERVIEW.equals(intentType)) {
|
|
|
|
|
} else if (INTENT_TYPE_TEXT_CASE_OVERVIEW.equals(query)) {
|
|
|
|
|
type = QA_TYPE_NX_LLM;
|
|
|
|
|
intentType = INTENT_TYPE_CASE_OVERVIEW;
|
|
|
|
|
answerMap.put("answerText", modelCaseService.getById(caseId).getCaseDetail());
|
|
|
|
|
} else if (INTENT_TYPE_TEXT_CASE_EVIDENCE_GUIDE.equals(query) || INTENT_TYPE_CASE_EVIDENCE_GUIDE.equals(intentType)) {
|
|
|
|
|
} else if (INTENT_TYPE_TEXT_CASE_EVIDENCE_GUIDE.equals(query)) {
|
|
|
|
|
type = QA_TYPE_NX_LLM;
|
|
|
|
|
intentType = INTENT_TYPE_CASE_EVIDENCE_GUIDE;
|
|
|
|
|
answerMap.put("guideDesc", modelService.caseScoreDetail(caseId).getGuideDesc());
|
|
|
|
@ -147,42 +148,40 @@ public class ChatServiceImpl implements ChatService {
|
|
|
|
|
difyChatReqVO.setUser(userId);
|
|
|
|
|
difyChatReqVO.setConversationId(chatReqVO.getConversationId());
|
|
|
|
|
difyChatReqVO.setQuery(query);
|
|
|
|
|
difyChatReqVO.setInputs(Map.of("dataset_id", modelCase.getKnowledgeBaseId(), "participator", modelCase.getLawActor()));
|
|
|
|
|
DifyChatResVO chat = difyApiUtil.chat(difyChatReqVO);
|
|
|
|
|
JSONObject json = JSON.parseObject(chat.getAnswer());
|
|
|
|
|
chatResVO.setAnswer(json.getString("answerText"));
|
|
|
|
|
chatResVO.setSegmentList(JSONArray.parseArray(json.getString("quote"), KnowledgeBaseSegmentVO.class));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case QA_TYPE_NX_LLM:
|
|
|
|
|
switch (intentType) {
|
|
|
|
|
case INTENT_TYPE_INDEX_RESULT:
|
|
|
|
|
if (modelIndices.stream().map(ModelIndex::getName).anyMatch(query::equals)) {
|
|
|
|
|
handleIndexResultQA(modelIndices, query, caseId, answerMap);
|
|
|
|
|
DIFYChatReqInputVO inputs = new DIFYChatReqInputVO();
|
|
|
|
|
inputs.setCase_id(caseId);
|
|
|
|
|
inputs.setUser_id(userId);
|
|
|
|
|
inputs.setConversation_id(chatReqVO.getConversationId());
|
|
|
|
|
inputs.setDataset_id(modelCase.getKnowledgeBaseId());
|
|
|
|
|
inputs.setParticipator(modelCase.getLawActor());
|
|
|
|
|
inputs.setDialogue_count(chatReqVO.getDialogueCount());
|
|
|
|
|
inputs.setIntent_type(intentType);
|
|
|
|
|
difyChatReqVO.setInputs(inputs);
|
|
|
|
|
DifyChatResVO response = difyApiUtil.chat(difyChatReqVO);
|
|
|
|
|
log.info("response:{}", JSON.toJSONString(response));
|
|
|
|
|
// 拼装返回对象
|
|
|
|
|
JSONObject json = JSON.parseObject(response.getAnswer());
|
|
|
|
|
if (json != null) {
|
|
|
|
|
intentType = json.getString("intentType");
|
|
|
|
|
if (json.getBoolean("isFunctionCalling")) {
|
|
|
|
|
answerMap = executeIntent(json.getString("intentType"), caseId, query, answerMap, modelIndices);
|
|
|
|
|
} else {
|
|
|
|
|
answerMap.put("answerText", "暂无相关指标信息");
|
|
|
|
|
chatResVO.setAnswer(json.getString("answerText"));
|
|
|
|
|
chatResVO.setSegmentList(JSONArray.parseArray(json.getString("quote"), KnowledgeBaseSegmentVO.class));
|
|
|
|
|
int dialogueCount = json.getInteger("dialogueCount") != null ? json.getInteger("dialogueCount") : 0;
|
|
|
|
|
chatResVO.setDialogueCount(dialogueCount);
|
|
|
|
|
if (json.getInteger("dialogueCount") != null) {
|
|
|
|
|
answerMap.put("adviceList", json.getJSONArray("adviceList"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case INTENT_TYPE_CASE_RESULT:
|
|
|
|
|
ModelCase modelCase = modelCaseService.getById(caseId);
|
|
|
|
|
if (modelCase.getTotalScore() == null) {
|
|
|
|
|
log.info("案件【{}】尚未执行模型分析,现在开始执行", modelCase.getCaseName());
|
|
|
|
|
AnalyseCaseDTO analyseCaseDTO = new AnalyseCaseDTO();
|
|
|
|
|
analyseCaseDTO.setCaseId(caseId);
|
|
|
|
|
modelService.analyseCase(analyseCaseDTO);
|
|
|
|
|
}
|
|
|
|
|
answerMap = JSON.parseObject(JSON.toJSONString(modelService.caseScoreDetail(caseId)), Map.class);
|
|
|
|
|
break;
|
|
|
|
|
case INTENT_TYPE_CASE_OVERVIEW:
|
|
|
|
|
answerMap.put("answerText", modelCaseService.getById(caseId).getCaseDetail());
|
|
|
|
|
break;
|
|
|
|
|
case INTENT_TYPE_CASE_EVIDENCE_GUIDE:
|
|
|
|
|
answerMap.put("guideDesc", modelService.caseScoreDetail(caseId).getGuideDesc());
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
log.error("返回结果格式异常,query:【{}】", query);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case QA_TYPE_NX_LLM:
|
|
|
|
|
answerMap = executeIntent(intentType, caseId, query, answerMap, modelIndices);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -193,6 +192,7 @@ public class ChatServiceImpl implements ChatService {
|
|
|
|
|
long end = System.currentTimeMillis();
|
|
|
|
|
ConversationQa qa = new ConversationQa();
|
|
|
|
|
qa.setId(UUID.randomUUID().toString());
|
|
|
|
|
qa.setDialogCount(chatResVO.getDialogueCount());
|
|
|
|
|
qa.setQuestion(query);
|
|
|
|
|
qa.setQuestionTime(new Date(startTime));
|
|
|
|
|
qa.setAnswer(chatResVO.getAnswer());
|
|
|
|
@ -308,4 +308,35 @@ public class ChatServiceImpl implements ChatService {
|
|
|
|
|
answerMap.put("evidenceNames", evidenceList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> executeIntent(String intentType, String caseId, String query, Map<String, Object> answerMap, List<ModelIndex> modelIndices) {
|
|
|
|
|
switch (intentType) {
|
|
|
|
|
case INTENT_TYPE_INDEX_RESULT:
|
|
|
|
|
if (modelIndices.stream().map(ModelIndex::getName).anyMatch(query::equals)) {
|
|
|
|
|
handleIndexResultQA(modelIndices, query, caseId, answerMap);
|
|
|
|
|
} else {
|
|
|
|
|
answerMap.put("answerText", "暂无相关指标信息");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case INTENT_TYPE_CASE_RESULT:
|
|
|
|
|
ModelCase modelCase = modelCaseService.getById(caseId);
|
|
|
|
|
if (modelCase.getTotalScore() == null) {
|
|
|
|
|
log.info("案件【{}】尚未执行模型分析,现在开始执行", modelCase.getCaseName());
|
|
|
|
|
AnalyseCaseDTO analyseCaseDTO = new AnalyseCaseDTO();
|
|
|
|
|
analyseCaseDTO.setCaseId(caseId);
|
|
|
|
|
modelService.analyseCase(analyseCaseDTO);
|
|
|
|
|
}
|
|
|
|
|
answerMap = JSON.parseObject(JSON.toJSONString(modelService.caseScoreDetail(caseId)), Map.class);
|
|
|
|
|
break;
|
|
|
|
|
case INTENT_TYPE_CASE_OVERVIEW:
|
|
|
|
|
answerMap.put("answerText", modelCaseService.getById(caseId).getCaseDetail());
|
|
|
|
|
break;
|
|
|
|
|
case INTENT_TYPE_CASE_EVIDENCE_GUIDE:
|
|
|
|
|
answerMap.put("guideDesc", modelService.caseScoreDetail(caseId).getGuideDesc());
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return answerMap;
|
|
|
|
|
}
|
|
|
|
|
}
|