问题修复

jinan_dev
yaxin 5 months ago
parent 619f5b162b
commit 868a71364c

@ -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);

@ -115,8 +115,7 @@ public class ModelServiceImpl implements ModelService {
CasePerson casePerson = casePersonMapper.selectOne(new LambdaQueryWrapper<CasePerson>()
.eq(CasePerson::getCaseId, caseId)
.eq(CasePerson::getCaseActorFlag, 1)
.eq(CasePerson::getRoleCode, "1")
.eq(StrUtil.isNotEmpty(modelCase.getLawActor()), CasePerson::getName, modelCase.getLawActor()));
.eq(CasePerson::getRoleCode, "1"));
if (ObjectUtil.isEmpty(casePerson)) {
log.error("未找到的行为人:【{}】", modelCase.getLawActor());
return R.fail("未找到的行为人");

@ -1,7 +1,5 @@
package com.supervision.demo;
import com.supervision.common.constant.DifyConstants;
import com.supervision.police.domain.ConversationQa;
import com.supervision.police.vo.dify.DifyChatReqVO;
import com.supervision.utils.DifyApiUtil;
import com.supervision.utils.Document;
@ -10,7 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
import java.util.Map;
@SpringBootTest
public class DifyTest {
@ -43,9 +40,7 @@ public class DifyTest {
System.out.println("Test");
DifyChatReqVO difyChatReqVO = new DifyChatReqVO();
difyChatReqVO.setUser("admin");
// chatReqVO.setQuery("Who are you?");
difyChatReqVO.setQuery("裴金禄的户籍地址");
difyChatReqVO.setInputs(Map.of("dataset_id", "13c60b8c-341f-43ea-b3cc-5289a518abd9"));
System.out.println(difyApiUtil.chat(difyChatReqVO));
}
@ -57,7 +52,7 @@ public class DifyTest {
}
@Test
public void createDocumentByTextTest(){
public void createDocumentByTextTest() {
String documentId = difyApiUtil.createDocumentByText("d5da0a24-a8e9-4ceb-8004-6da4847fbb04", "test-text", "坚定不移中国特色社会主义道路");
System.out.println(documentId);
}

Loading…
Cancel
Save