|
|
|
@ -7,6 +7,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.supervision.chat.client.LangChainChatService;
|
|
|
|
@ -53,7 +54,7 @@ public class ChatServiceImpl implements ChatService {
|
|
|
|
|
private final ConversationQaService conversationQaService;
|
|
|
|
|
private final ModelIndexService modelIndexService;
|
|
|
|
|
private final DifyApiUtil difyApiUtil;
|
|
|
|
|
private final NoteRecordService noteRecordService;
|
|
|
|
|
private final ComDictionaryService comDictionaryService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -116,7 +117,8 @@ public class ChatServiceImpl implements ChatService {
|
|
|
|
|
conversationService.updateById(conversation);
|
|
|
|
|
log.info("会话已更新,conversationId:{}", conversation.getId());
|
|
|
|
|
}
|
|
|
|
|
List<ModelIndex> modelIndices = modelIndexService.list();
|
|
|
|
|
List<ModelIndex> modelIndices = modelIndexService.list(new LambdaQueryWrapper<ModelIndex>().eq(ModelIndex::getDataStatus, "1"));
|
|
|
|
|
Map<String, String> indexType = comDictionaryService.getDictionaryMap("index_type");
|
|
|
|
|
switch (type) {
|
|
|
|
|
case QA_TYPE_DIFY:
|
|
|
|
|
if (modelIndices.stream().map(ModelIndex::getName).anyMatch(query::equals)) {
|
|
|
|
@ -164,15 +166,30 @@ public class ChatServiceImpl implements ChatService {
|
|
|
|
|
if (json != null) {
|
|
|
|
|
intentType = json.getString("intentType");
|
|
|
|
|
if (json.getBoolean("isFunctionCalling")) {
|
|
|
|
|
answerMap = executeIntent(json.getString("intentType"), caseId, query, answerMap, modelIndices);
|
|
|
|
|
answerMap = executeIntent(json.getString("intentType"), caseId, json.getString("query"), answerMap, modelIndices);
|
|
|
|
|
} else {
|
|
|
|
|
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"));
|
|
|
|
|
chatResVO.setDialogueCount(json.getInteger("dialogueCount") == null ? 0 : json.getInteger("dialogueCount"));
|
|
|
|
|
}
|
|
|
|
|
JSONArray adviceList = json.getJSONArray("adviceList");
|
|
|
|
|
if (adviceList != null && !adviceList.isEmpty()) {
|
|
|
|
|
List<Map<String, String>> adviceMapList = new ArrayList<>();
|
|
|
|
|
// 遍历adviceList里的指标名称,尝试在modelIndices集合中找到name匹配的指标,并根据indexType更新当前指标名称,在字符串前插入对应的指标类型
|
|
|
|
|
for (int i = 0; i < adviceList.size(); i++) {
|
|
|
|
|
String advice = adviceList.getString(i);
|
|
|
|
|
for (ModelIndex modelIndex : modelIndices) {
|
|
|
|
|
if (advice.contains(modelIndex.getName())) {
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
|
map.put("indexType", indexType.get(modelIndex.getIndexType()));
|
|
|
|
|
map.put("indexName", modelIndex.getName());
|
|
|
|
|
adviceMapList.add(map);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
adviceMapList.add(Map.of("indexType", "", "indexName", "以上都不是"));
|
|
|
|
|
answerMap.put("adviceList", adviceMapList);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.error("返回结果格式异常,query:【{}】", query);
|
|
|
|
|