mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 03:58:14 +00:00
(improvement)(chat) add traceId and time cost for show (#272)
This commit is contained in:
@@ -22,6 +22,7 @@ public class ParseResp {
|
||||
private List<SemanticParseInfo> selectedParses;
|
||||
private List<SemanticParseInfo> candidateParses;
|
||||
private List<SolvedQueryRecallResp> similarSolvedQuery;
|
||||
private ParseTimeCostDO parseTimeCost;
|
||||
|
||||
public enum ParseState {
|
||||
COMPLETED,
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.tencent.supersonic.chat.api.pojo.response;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ParseTimeCostDO {
|
||||
private Long parseTime;
|
||||
private Long sqlTime;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.tencent.supersonic.chat.api.pojo.response;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class QueryRecallResp {
|
||||
private List<SolvedQueryRecallResp> solvedQueryRecallRespList;
|
||||
private Long queryTimeCost;
|
||||
}
|
||||
@@ -21,4 +21,5 @@ public class QueryResult {
|
||||
private SemanticParseInfo chatContext;
|
||||
private Object response;
|
||||
private List<Map<String, Object>> queryResults;
|
||||
private Long queryTimeCost;
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ public class LLMS2QLParser implements SemanticParser {
|
||||
}
|
||||
|
||||
private List<QueryFilter> getDimensionFilter(Map<String, SchemaElement> fieldNameToElement,
|
||||
List<FilterExpression> filterExpressions) {
|
||||
List<FilterExpression> filterExpressions) {
|
||||
List<QueryFilter> result = Lists.newArrayList();
|
||||
for (FilterExpression expression : filterExpressions) {
|
||||
QueryFilter dimensionFilter = new QueryFilter();
|
||||
@@ -229,7 +229,7 @@ public class LLMS2QLParser implements SemanticParser {
|
||||
}
|
||||
|
||||
private boolean containOperators(FilterExpression expression, FilterOperatorEnum firstOperator,
|
||||
FilterOperatorEnum... operatorEnums) {
|
||||
FilterOperatorEnum... operatorEnums) {
|
||||
return (Arrays.asList(operatorEnums).contains(firstOperator) && Objects.nonNull(expression.getFieldValue()));
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ public class LLMS2QLParser implements SemanticParser {
|
||||
}
|
||||
|
||||
private SemanticParseInfo getParseInfo(QueryContext queryCtx, Long modelId, CommonAgentTool commonAgentTool,
|
||||
ParseResult parseResult) {
|
||||
ParseResult parseResult) {
|
||||
PluginSemanticQuery semanticQuery = QueryManager.createPluginQuery(S2QLQuery.QUERY_MODE);
|
||||
SemanticParseInfo parseInfo = semanticQuery.getParseInfo();
|
||||
parseInfo.getElementMatches().addAll(queryCtx.getMapInfo().getMatchedElements(modelId));
|
||||
@@ -414,7 +414,7 @@ public class LLMS2QLParser implements SemanticParser {
|
||||
|
||||
|
||||
protected List<String> getFieldNameList(QueryContext queryCtx, Long modelId, SemanticSchema semanticSchema,
|
||||
LLMParserConfig llmParserConfig) {
|
||||
LLMParserConfig llmParserConfig) {
|
||||
|
||||
Set<String> results = getTopNFieldNames(modelId, semanticSchema, llmParserConfig);
|
||||
|
||||
@@ -450,7 +450,7 @@ public class LLMS2QLParser implements SemanticParser {
|
||||
}
|
||||
|
||||
private Set<String> getTopNFieldNames(Long modelId, SemanticSchema semanticSchema,
|
||||
LLMParserConfig llmParserConfig) {
|
||||
LLMParserConfig llmParserConfig) {
|
||||
Set<String> results = semanticSchema.getDimensions(modelId).stream()
|
||||
.sorted(Comparator.comparing(SchemaElement::getUseCnt).reversed())
|
||||
.limit(llmParserConfig.getDimensionTopN())
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||
import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.chat.api.pojo.request.QueryReq;
|
||||
import com.tencent.supersonic.chat.api.pojo.response.ParseResp;
|
||||
import com.tencent.supersonic.chat.api.pojo.response.ParseTimeCostDO;
|
||||
import com.tencent.supersonic.chat.persistence.dataobject.ChatParseDO;
|
||||
import com.tencent.supersonic.chat.query.QueryManager;
|
||||
import com.tencent.supersonic.common.util.JsonUtil;
|
||||
@@ -22,8 +23,11 @@ public class ExplainSqlParseResponder implements ParseResponder {
|
||||
public void fillResponse(ParseResp parseResp, QueryContext queryContext,
|
||||
List<ChatParseDO> chatParseDOS) {
|
||||
QueryReq queryReq = queryContext.getRequest();
|
||||
Long startTime = System.currentTimeMillis();
|
||||
addExplainSql(queryReq, parseResp.getSelectedParses());
|
||||
addExplainSql(queryReq, parseResp.getCandidateParses());
|
||||
parseResp.setParseTimeCost(new ParseTimeCostDO());
|
||||
parseResp.getParseTimeCost().setSqlTime(System.currentTimeMillis() - startTime);
|
||||
if (!CollectionUtils.isEmpty(chatParseDOS)) {
|
||||
Map<Integer, ChatParseDO> chatParseDOMap = chatParseDOS.stream()
|
||||
.collect(Collectors.toMap(ChatParseDO::getParseId,
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.tencent.supersonic.chat.rest;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
|
||||
import com.tencent.supersonic.chat.api.pojo.response.QueryRecallResp;
|
||||
import com.tencent.supersonic.chat.api.pojo.response.ShowCaseResp;
|
||||
import com.tencent.supersonic.chat.api.pojo.response.SolvedQueryRecallResp;
|
||||
import com.tencent.supersonic.chat.persistence.dataobject.ChatDO;
|
||||
@@ -89,7 +90,12 @@ public class ChatController {
|
||||
@RequestMapping("/getSolvedQuery")
|
||||
public List<SolvedQueryRecallResp> getSolvedQuery(@RequestParam(value = "queryText") String queryText,
|
||||
@RequestParam(value = "agentId") Integer agentId) {
|
||||
return chatService.getSolvedQuery(queryText, agentId);
|
||||
QueryRecallResp queryRecallResp = new QueryRecallResp();
|
||||
Long startTime = System.currentTimeMillis();
|
||||
List<SolvedQueryRecallResp> solvedQueryRecallRespList = chatService.getSolvedQuery(queryText, agentId);
|
||||
queryRecallResp.setSolvedQueryRecallRespList(solvedQueryRecallRespList);
|
||||
queryRecallResp.setQueryTimeCost(System.currentTimeMillis() - startTime);
|
||||
return solvedQueryRecallRespList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -112,6 +112,7 @@ public class QueryServiceImpl implements QueryService {
|
||||
|
||||
@Override
|
||||
public ParseResp performParsing(QueryReq queryReq) {
|
||||
Long parseTime = System.currentTimeMillis();
|
||||
QueryContext queryCtx = new QueryContext(queryReq);
|
||||
// in order to support multi-turn conversation, chat context is needed
|
||||
ChatContext chatCtx = chatService.getOrCreateContext(queryReq.getChatId());
|
||||
@@ -169,6 +170,8 @@ public class QueryServiceImpl implements QueryService {
|
||||
queryReq.getUser().getName(), queryReq.getChatId().longValue());
|
||||
}
|
||||
chatService.updateChatParse(chatParseDOS);
|
||||
parseResult.getParseTimeCost().setParseTime(
|
||||
System.currentTimeMillis() - parseTime - parseResult.getParseTimeCost().getSqlTime());
|
||||
return parseResult;
|
||||
}
|
||||
|
||||
@@ -204,6 +207,7 @@ public class QueryServiceImpl implements QueryService {
|
||||
|
||||
@Override
|
||||
public QueryResult performExecution(ExecuteQueryReq queryReq) throws Exception {
|
||||
Long executeTime = System.currentTimeMillis();
|
||||
ChatParseDO chatParseDO = chatService.getParseInfo(queryReq.getQueryId(),
|
||||
queryReq.getParseId());
|
||||
ChatQueryDO chatQueryDO = chatService.getLastQuery(queryReq.getChatId());
|
||||
@@ -224,6 +228,7 @@ public class QueryServiceImpl implements QueryService {
|
||||
if (queryResult != null) {
|
||||
timeCostDOList.add(StatisticsDO.builder().cost((int) (System.currentTimeMillis() - startTime))
|
||||
.interfaceName(semanticQuery.getClass().getSimpleName()).type(CostType.QUERY.getType()).build());
|
||||
queryResult.setQueryTimeCost(timeCostDOList.get(0).getCost().longValue());
|
||||
saveInfo(timeCostDOList, queryReq.getQueryText(), queryReq.getQueryId(),
|
||||
queryReq.getUser().getName(), queryReq.getChatId().longValue());
|
||||
queryResult.setChatContext(parseInfo);
|
||||
@@ -242,7 +247,7 @@ public class QueryServiceImpl implements QueryService {
|
||||
} else {
|
||||
chatService.deleteChatQuery(queryReq.getQueryId());
|
||||
}
|
||||
|
||||
queryResult.setQueryTimeCost(System.currentTimeMillis() - executeTime);
|
||||
return queryResult;
|
||||
}
|
||||
|
||||
@@ -349,20 +354,14 @@ public class QueryServiceImpl implements QueryService {
|
||||
parseInfo.getDimensionFilters(), addWhereConditions, removeWhereFieldNames);
|
||||
updateDateInfo(queryData, parseInfo, filedNameToValueMap,
|
||||
whereExpressionList, addWhereConditions, removeWhereFieldNames);
|
||||
log.info("filedNameToValueMap:{}", filedNameToValueMap);
|
||||
log.info("removeWhereFieldNames:{}", removeWhereFieldNames);
|
||||
correctorSql = SqlParserReplaceHelper.replaceValue(correctorSql, filedNameToValueMap);
|
||||
correctorSql = SqlParserRemoveHelper.removeWhereCondition(correctorSql, removeWhereFieldNames);
|
||||
|
||||
updateFilters(havingFiledNameToValueMap, havingExpressionList, queryData.getDimensionFilters(),
|
||||
parseInfo.getDimensionFilters(), addHavingConditions, removeHavingFieldNames);
|
||||
log.info("havingFiledNameToValueMap:{}", havingFiledNameToValueMap);
|
||||
log.info("removeHavingFieldNames:{}", removeHavingFieldNames);
|
||||
correctorSql = SqlParserReplaceHelper.replaceHavingValue(correctorSql, havingFiledNameToValueMap);
|
||||
correctorSql = SqlParserRemoveHelper.removeHavingCondition(correctorSql, removeHavingFieldNames);
|
||||
|
||||
log.info("addWhereConditions:{}", addWhereConditions);
|
||||
log.info("addHavingConditions:{}", addHavingConditions);
|
||||
correctorSql = SqlParserAddHelper.addWhere(correctorSql, addWhereConditions);
|
||||
correctorSql = SqlParserAddHelper.addHaving(correctorSql, addHavingConditions);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user