mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 12:37:55 +00:00
(improvement)(chat) show case fill candidate parse (#267)
Co-authored-by: jolunoluo
This commit is contained in:
@@ -138,25 +138,7 @@ public class ChatServiceImpl implements ChatService {
|
|||||||
if (CollectionUtils.isEmpty(queryRespPageInfo.getList())) {
|
if (CollectionUtils.isEmpty(queryRespPageInfo.getList())) {
|
||||||
return queryRespPageInfo;
|
return queryRespPageInfo;
|
||||||
}
|
}
|
||||||
List<Long> queryIds = queryRespPageInfo.getList().stream()
|
fillParseInfo(queryRespPageInfo.getList());
|
||||||
.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);
|
|
||||||
}
|
|
||||||
return queryRespPageInfo;
|
return queryRespPageInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,12 +164,36 @@ public class ChatServiceImpl implements ChatService {
|
|||||||
Map<String, Object> data = queryResp.getQueryResult().getQueryResults().get(0);
|
Map<String, Object> data = queryResp.getQueryResult().getQueryResults().get(0);
|
||||||
return CollectionUtils.isEmpty(data);
|
return CollectionUtils.isEmpty(data);
|
||||||
});
|
});
|
||||||
|
fillParseInfo(queryResps);
|
||||||
Map<Long, List<QueryResp>> showCaseMap = queryResps.stream()
|
Map<Long, List<QueryResp>> showCaseMap = queryResps.stream()
|
||||||
.collect(Collectors.groupingBy(QueryResp::getChatId));
|
.collect(Collectors.groupingBy(QueryResp::getChatId));
|
||||||
showCaseResp.setShowCaseMap(showCaseMap);
|
showCaseResp.setShowCaseMap(showCaseMap);
|
||||||
return showCaseResp;
|
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
|
@Override
|
||||||
public void addQuery(QueryResult queryResult, ChatContext chatCtx) {
|
public void addQuery(QueryResult queryResult, ChatContext chatCtx) {
|
||||||
chatQueryRepository.createChatQuery(queryResult, chatCtx);
|
chatQueryRepository.createChatQuery(queryResult, chatCtx);
|
||||||
|
|||||||
Reference in New Issue
Block a user