(improvement)(chat) show case fill candidate parse (#267)

Co-authored-by: jolunoluo
This commit is contained in:
LXW
2023-10-20 16:09:50 +08:00
committed by GitHub
parent dd63b78937
commit d710986923

View File

@@ -138,25 +138,7 @@ public class ChatServiceImpl implements ChatService {
if (CollectionUtils.isEmpty(queryRespPageInfo.getList())) {
return queryRespPageInfo;
}
List<Long> queryIds = queryRespPageInfo.getList().stream()
.map(QueryResp::getQuestionId).collect(Collectors.toList());
List<ChatParseDO> chatParseDOs = chatQueryRepository.getParseInfoList(queryIds);
if (CollectionUtils.isEmpty(chatParseDOs)) {
return queryRespPageInfo;
}
Map<Long, List<ChatParseDO>> chatParseMap = chatParseDOs.stream()
.collect(Collectors.groupingBy(ChatParseDO::getQuestionId));
for (QueryResp queryResp : queryRespPageInfo.getList()) {
List<ChatParseDO> chatParseDOList = chatParseMap.get(queryResp.getQuestionId());
if (CollectionUtils.isEmpty(chatParseMap)) {
continue;
}
List<SemanticParseInfo> parseInfos = chatParseDOList.stream().map(chatParseDO ->
JsonUtil.toObject(chatParseDO.getParseInfo(), SemanticParseInfo.class))
.sorted(Comparator.comparingDouble(SemanticParseInfo::getScore).reversed())
.collect(Collectors.toList());
queryResp.setParseInfos(parseInfos);
}
fillParseInfo(queryRespPageInfo.getList());
return queryRespPageInfo;
}
@@ -182,12 +164,36 @@ public class ChatServiceImpl implements ChatService {
Map<String, Object> data = queryResp.getQueryResult().getQueryResults().get(0);
return CollectionUtils.isEmpty(data);
});
fillParseInfo(queryResps);
Map<Long, List<QueryResp>> showCaseMap = queryResps.stream()
.collect(Collectors.groupingBy(QueryResp::getChatId));
showCaseResp.setShowCaseMap(showCaseMap);
return showCaseResp;
}
private void fillParseInfo(List<QueryResp> queryResps) {
List<Long> queryIds = queryResps.stream()
.map(QueryResp::getQuestionId).collect(Collectors.toList());
List<ChatParseDO> chatParseDOs = chatQueryRepository.getParseInfoList(queryIds);
if (CollectionUtils.isEmpty(chatParseDOs)) {
return;
}
Map<Long, List<ChatParseDO>> chatParseMap = chatParseDOs.stream()
.collect(Collectors.groupingBy(ChatParseDO::getQuestionId));
for (QueryResp queryResp : queryResps) {
List<ChatParseDO> chatParseDOList = chatParseMap.get(queryResp.getQuestionId());
if (CollectionUtils.isEmpty(chatParseMap)) {
continue;
}
List<SemanticParseInfo> parseInfos = chatParseDOList.stream().map(chatParseDO ->
JsonUtil.toObject(chatParseDO.getParseInfo(), SemanticParseInfo.class))
.sorted(Comparator.comparingDouble(SemanticParseInfo::getScore).reversed())
.collect(Collectors.toList());
queryResp.setParseInfos(parseInfos);
}
}
@Override
public void addQuery(QueryResult queryResult, ChatContext chatCtx) {
chatQueryRepository.createChatQuery(queryResult, chatCtx);