mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 03:58:14 +00:00
[improvement][chat]Support user feedback to semantic parse info.#1729
This commit is contained in:
@@ -15,6 +15,10 @@ public class SchemaMapInfo {
|
||||
|
||||
private final Map<Long, List<SchemaElementMatch>> dataSetElementMatches = new HashMap<>();
|
||||
|
||||
public boolean isEmpty() {
|
||||
return dataSetElementMatches.keySet().isEmpty();
|
||||
}
|
||||
|
||||
public Set<Long> getMatchedDataSetInfos() {
|
||||
return dataSetElementMatches.keySet();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public class QueryNLReq extends SemanticQueryReq {
|
||||
private Map<String, ChatApp> chatAppConfig;
|
||||
private List<Text2SQLExemplar> dynamicExemplars = Lists.newArrayList();
|
||||
private SemanticParseInfo contextParseInfo;
|
||||
private SemanticParseInfo selectedParseInfo;
|
||||
|
||||
@Override
|
||||
public String toCustomizedString() {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.tencent.supersonic.common.util.ContextUtils;
|
||||
import com.tencent.supersonic.headless.api.pojo.DataSetSchema;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaMapInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticSchema;
|
||||
import com.tencent.supersonic.headless.api.pojo.enums.ChatWorkflowState;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.QueryNLReq;
|
||||
@@ -15,6 +16,7 @@ import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Data
|
||||
@@ -35,6 +37,10 @@ public class ChatQueryContext {
|
||||
|
||||
public ChatQueryContext(QueryNLReq request) {
|
||||
this.request = request;
|
||||
SemanticParseInfo parseInfo = request.getSelectedParseInfo();
|
||||
if (Objects.nonNull(parseInfo) && Objects.nonNull(parseInfo.getDataSetId())) {
|
||||
mapInfo.setMatchedElements(parseInfo.getDataSetId(), parseInfo.getElementMatches());
|
||||
}
|
||||
}
|
||||
|
||||
public List<SemanticQuery> getCandidateQueries() {
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticSchema;
|
||||
import com.tencent.supersonic.headless.api.pojo.SqlEvaluation;
|
||||
import com.tencent.supersonic.headless.api.pojo.SqlInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.enums.ChatWorkflowState;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.QueryMapReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.QueryNLReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.QuerySqlReq;
|
||||
@@ -87,7 +88,11 @@ public class S2ChatLayerService implements ChatLayerService {
|
||||
public ParseResp parse(QueryNLReq queryNLReq) {
|
||||
ParseResp parseResult = new ParseResp(queryNLReq.getQueryText());
|
||||
ChatQueryContext queryCtx = buildChatQueryContext(queryNLReq);
|
||||
chatWorkflowEngine.start(queryCtx, parseResult);
|
||||
if (queryCtx.getMapInfo().isEmpty()) {
|
||||
chatWorkflowEngine.start(ChatWorkflowState.MAPPING, queryCtx, parseResult);
|
||||
} else {
|
||||
chatWorkflowEngine.start(ChatWorkflowState.PARSING, queryCtx, parseResult);
|
||||
}
|
||||
return parseResult;
|
||||
}
|
||||
|
||||
@@ -113,6 +118,7 @@ public class S2ChatLayerService implements ChatLayerService {
|
||||
Map<Long, List<Long>> modelIdToDataSetIds = dataSetService.getModelIdToDataSetIds();
|
||||
queryCtx.setSemanticSchema(semanticSchema);
|
||||
queryCtx.setModelIdToDataSetIds(modelIdToDataSetIds);
|
||||
|
||||
return queryCtx;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,13 +36,14 @@ public class ChatWorkflowEngine {
|
||||
ComponentFactory.getSemanticCorrectors();
|
||||
private final List<ResultProcessor> resultProcessors = ComponentFactory.getResultProcessors();
|
||||
|
||||
public void start(ChatQueryContext queryCtx, ParseResp parseResult) {
|
||||
queryCtx.setChatWorkflowState(ChatWorkflowState.MAPPING);
|
||||
public void start(ChatWorkflowState initialState, ChatQueryContext queryCtx,
|
||||
ParseResp parseResult) {
|
||||
queryCtx.setChatWorkflowState(initialState);
|
||||
while (queryCtx.getChatWorkflowState() != ChatWorkflowState.FINISHED) {
|
||||
switch (queryCtx.getChatWorkflowState()) {
|
||||
case MAPPING:
|
||||
performMapping(queryCtx);
|
||||
if (queryCtx.getMapInfo().getMatchedDataSetInfos().isEmpty()) {
|
||||
if (queryCtx.getMapInfo().isEmpty()) {
|
||||
parseResult.setState(ParseResp.ParseState.FAILED);
|
||||
parseResult.setErrorMsg(
|
||||
"No semantic entities can be mapped against user question.");
|
||||
|
||||
Reference in New Issue
Block a user