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:
@@ -19,4 +19,6 @@ public class ChatParseReq {
|
|||||||
private QueryFilters queryFilters;
|
private QueryFilters queryFilters;
|
||||||
private boolean saveAnswer = true;
|
private boolean saveAnswer = true;
|
||||||
private boolean disableLLM = false;
|
private boolean disableLLM = false;
|
||||||
|
private Long queryId;
|
||||||
|
private Integer parseId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.tencent.supersonic.chat.server.parser;
|
package com.tencent.supersonic.chat.server.parser;
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ChatParseReq;
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.response.QueryResp;
|
import com.tencent.supersonic.chat.api.pojo.response.QueryResp;
|
||||||
import com.tencent.supersonic.chat.server.pojo.ChatContext;
|
import com.tencent.supersonic.chat.server.pojo.ChatContext;
|
||||||
import com.tencent.supersonic.chat.server.pojo.ParseContext;
|
import com.tencent.supersonic.chat.server.pojo.ParseContext;
|
||||||
@@ -17,10 +16,12 @@ import com.tencent.supersonic.common.util.ContextUtils;
|
|||||||
import com.tencent.supersonic.headless.api.pojo.SchemaElementMatch;
|
import com.tencent.supersonic.headless.api.pojo.SchemaElementMatch;
|
||||||
import com.tencent.supersonic.headless.api.pojo.SchemaElementType;
|
import com.tencent.supersonic.headless.api.pojo.SchemaElementType;
|
||||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||||
|
import com.tencent.supersonic.headless.api.pojo.enums.MapModeEnum;
|
||||||
import com.tencent.supersonic.headless.api.pojo.request.QueryNLReq;
|
import com.tencent.supersonic.headless.api.pojo.request.QueryNLReq;
|
||||||
import com.tencent.supersonic.headless.api.pojo.response.MapResp;
|
import com.tencent.supersonic.headless.api.pojo.response.MapResp;
|
||||||
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
||||||
import com.tencent.supersonic.headless.api.pojo.response.QueryState;
|
import com.tencent.supersonic.headless.api.pojo.response.QueryState;
|
||||||
|
import com.tencent.supersonic.headless.chat.parser.ParserConfig;
|
||||||
import com.tencent.supersonic.headless.server.facade.service.ChatLayerService;
|
import com.tencent.supersonic.headless.server.facade.service.ChatLayerService;
|
||||||
import com.tencent.supersonic.headless.server.utils.ModelConfigHelper;
|
import com.tencent.supersonic.headless.server.utils.ModelConfigHelper;
|
||||||
import dev.langchain4j.data.message.AiMessage;
|
import dev.langchain4j.data.message.AiMessage;
|
||||||
@@ -74,37 +75,48 @@ public class NL2SQLParser implements ChatQueryParser {
|
|||||||
if (!parseContext.enableNL2SQL() || Objects.isNull(parseContext.getAgent())) {
|
if (!parseContext.enableNL2SQL() || Objects.isNull(parseContext.getAgent())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QueryNLReq queryNLReq = QueryReqConverter.buildQueryNLReq(parseContext);
|
if (parseContext.enableFeedback()) {
|
||||||
if (Objects.isNull(queryNLReq)) {
|
processFeedback(parseContext);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ParseResp parseResp = parseContext.getResponse();
|
|
||||||
ChatParseReq parseReq = parseContext.getRequest();
|
|
||||||
|
|
||||||
if (!parseContext.getRequest().isDisableLLM() && queryNLReq.getText2SQLType().enableLLM()) {
|
|
||||||
processMultiTurn(parseContext);
|
|
||||||
addDynamicExemplars(parseContext.getAgent().getId(), queryNLReq);
|
|
||||||
parseResp.setUsedExemplars(queryNLReq.getDynamicExemplars());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
QueryNLReq queryNLReq = QueryReqConverter.buildQueryNLReq(parseContext);
|
||||||
ChatContextService chatContextService = ContextUtils.getBean(ChatContextService.class);
|
ChatContextService chatContextService = ContextUtils.getBean(ChatContextService.class);
|
||||||
ChatContext chatCtx = chatContextService.getOrCreateContext(parseReq.getChatId());
|
ChatContext chatCtx =
|
||||||
if (chatCtx != null) {
|
chatContextService.getOrCreateContext(parseContext.getRequest().getChatId());
|
||||||
|
if (chatCtx != null && Objects.isNull(queryNLReq.getContextParseInfo())) {
|
||||||
queryNLReq.setContextParseInfo(chatCtx.getParseInfo());
|
queryNLReq.setContextParseInfo(chatCtx.getParseInfo());
|
||||||
}
|
}
|
||||||
|
if (parseContext.enableLLM()) {
|
||||||
ChatLayerService chatLayerService = ContextUtils.getBean(ChatLayerService.class);
|
rewriteMultiTurn(parseContext, queryNLReq);
|
||||||
ParseResp text2SqlParseResp = chatLayerService.parse(queryNLReq);
|
addDynamicExemplars(parseContext, queryNLReq);
|
||||||
if (ParseResp.ParseState.COMPLETED.equals(text2SqlParseResp.getState())) {
|
|
||||||
parseResp.getSelectedParses().addAll(text2SqlParseResp.getSelectedParses());
|
|
||||||
}
|
}
|
||||||
parseResp.setErrorMsg(text2SqlParseResp.getErrorMsg());
|
|
||||||
parseResp.setState(text2SqlParseResp.getState());
|
ParseResp parseResp = parseContext.getResponse();
|
||||||
parseResp.getParseTimeCost().setSqlTime(text2SqlParseResp.getParseTimeCost().getSqlTime());
|
doParse(queryNLReq, parseResp);
|
||||||
parseResp.setErrorMsg(text2SqlParseResp.getErrorMsg());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processMultiTurn(ParseContext parseContext) {
|
private void processFeedback(ParseContext parseContext) {
|
||||||
|
QueryNLReq queryNLReq = QueryReqConverter.buildQueryNLReq(parseContext);
|
||||||
|
ParseResp parseResp = parseContext.getResponse();
|
||||||
|
for (MapModeEnum mode : MapModeEnum.values()) {
|
||||||
|
queryNLReq.setMapModeEnum(mode);
|
||||||
|
doParse(queryNLReq, parseResp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doParse(QueryNLReq req, ParseResp resp) {
|
||||||
|
ChatLayerService chatLayerService = ContextUtils.getBean(ChatLayerService.class);
|
||||||
|
ParseResp text2SqlParseResp = chatLayerService.parse(req);
|
||||||
|
if (text2SqlParseResp.getState().equals(ParseResp.ParseState.COMPLETED)) {
|
||||||
|
resp.getSelectedParses().addAll(text2SqlParseResp.getSelectedParses());
|
||||||
|
}
|
||||||
|
resp.setState(text2SqlParseResp.getState());
|
||||||
|
resp.setParseTimeCost(text2SqlParseResp.getParseTimeCost());
|
||||||
|
resp.setErrorMsg(text2SqlParseResp.getErrorMsg());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rewriteMultiTurn(ParseContext parseContext, QueryNLReq queryNLReq) {
|
||||||
ChatApp chatApp = parseContext.getAgent().getChatAppConfig().get(APP_KEY_MULTI_TURN);
|
ChatApp chatApp = parseContext.getAgent().getChatAppConfig().get(APP_KEY_MULTI_TURN);
|
||||||
if (Objects.isNull(chatApp) || !chatApp.isEnable()) {
|
if (Objects.isNull(chatApp) || !chatApp.isEnable()) {
|
||||||
return;
|
return;
|
||||||
@@ -112,7 +124,6 @@ public class NL2SQLParser implements ChatQueryParser {
|
|||||||
|
|
||||||
// derive mapping result of current question and parsing result of last question.
|
// derive mapping result of current question and parsing result of last question.
|
||||||
ChatLayerService chatLayerService = ContextUtils.getBean(ChatLayerService.class);
|
ChatLayerService chatLayerService = ContextUtils.getBean(ChatLayerService.class);
|
||||||
QueryNLReq queryNLReq = QueryReqConverter.buildQueryNLReq(parseContext);
|
|
||||||
MapResp currentMapResult = chatLayerService.map(queryNLReq);
|
MapResp currentMapResult = chatLayerService.map(queryNLReq);
|
||||||
|
|
||||||
List<QueryResp> historyQueries =
|
List<QueryResp> historyQueries =
|
||||||
@@ -143,6 +154,7 @@ public class NL2SQLParser implements ChatQueryParser {
|
|||||||
String rewrittenQuery = response.content().text();
|
String rewrittenQuery = response.content().text();
|
||||||
keyPipelineLog.info("QueryRewrite modelReq:\n{} \nmodelResp:\n{}", prompt.text(), response);
|
keyPipelineLog.info("QueryRewrite modelReq:\n{} \nmodelResp:\n{}", prompt.text(), response);
|
||||||
parseContext.getRequest().setQueryText(rewrittenQuery);
|
parseContext.getRequest().setQueryText(rewrittenQuery);
|
||||||
|
queryNLReq.setQueryText(rewrittenQuery);
|
||||||
log.info("Last Query: {} Current Query: {}, Rewritten Query: {}", lastQuery.getQueryText(),
|
log.info("Last Query: {} Current Query: {}, Rewritten Query: {}", lastQuery.getQueryText(),
|
||||||
currentMapResult.getQueryText(), rewrittenQuery);
|
currentMapResult.getQueryText(), rewrittenQuery);
|
||||||
}
|
}
|
||||||
@@ -185,15 +197,17 @@ public class NL2SQLParser implements ChatQueryParser {
|
|||||||
return contextualList;
|
return contextualList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addDynamicExemplars(Integer agentId, QueryNLReq queryNLReq) {
|
private void addDynamicExemplars(ParseContext parseContext, QueryNLReq queryNLReq) {
|
||||||
ExemplarServiceImpl exemplarManager = ContextUtils.getBean(ExemplarServiceImpl.class);
|
ExemplarServiceImpl exemplarManager = ContextUtils.getBean(ExemplarServiceImpl.class);
|
||||||
EmbeddingConfig embeddingConfig = ContextUtils.getBean(EmbeddingConfig.class);
|
EmbeddingConfig embeddingConfig = ContextUtils.getBean(EmbeddingConfig.class);
|
||||||
String memoryCollectionName = embeddingConfig.getMemoryCollectionName(agentId);
|
String memoryCollectionName =
|
||||||
|
embeddingConfig.getMemoryCollectionName(parseContext.getAgent().getId());
|
||||||
ParserConfig parserConfig = ContextUtils.getBean(ParserConfig.class);
|
ParserConfig parserConfig = ContextUtils.getBean(ParserConfig.class);
|
||||||
int exemplarRecallNumber =
|
int exemplarRecallNumber =
|
||||||
Integer.parseInt(parserConfig.getParameterValue(PARSER_EXEMPLAR_RECALL_NUMBER));
|
Integer.parseInt(parserConfig.getParameterValue(PARSER_EXEMPLAR_RECALL_NUMBER));
|
||||||
List<Text2SQLExemplar> exemplars = exemplarManager.recallExemplars(memoryCollectionName,
|
List<Text2SQLExemplar> exemplars = exemplarManager.recallExemplars(memoryCollectionName,
|
||||||
queryNLReq.getQueryText(), exemplarRecallNumber);
|
queryNLReq.getQueryText(), exemplarRecallNumber);
|
||||||
queryNLReq.getDynamicExemplars().addAll(exemplars);
|
queryNLReq.getDynamicExemplars().addAll(exemplars);
|
||||||
|
parseContext.getResponse().setUsedExemplars(exemplars);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.tencent.supersonic.chat.server.parser;
|
|
||||||
|
|
||||||
import com.tencent.supersonic.common.config.ParameterConfig;
|
|
||||||
import com.tencent.supersonic.common.pojo.Parameter;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service("ChatQueryParserConfig")
|
|
||||||
@Slf4j
|
|
||||||
public class ParserConfig extends ParameterConfig {
|
|
||||||
|
|
||||||
public static final Parameter PARSER_MULTI_TURN_ENABLE =
|
|
||||||
new Parameter("s2.parser.multi-turn.enable", "false", "是否开启多轮对话", "开启多轮对话将消耗更多token",
|
|
||||||
"bool", "语义解析配置");
|
|
||||||
}
|
|
||||||
@@ -2,14 +2,18 @@ package com.tencent.supersonic.chat.server.pojo;
|
|||||||
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ChatParseReq;
|
import com.tencent.supersonic.chat.api.pojo.request.ChatParseReq;
|
||||||
import com.tencent.supersonic.chat.server.agent.Agent;
|
import com.tencent.supersonic.chat.server.agent.Agent;
|
||||||
|
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||||
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ParseContext {
|
public class ParseContext {
|
||||||
private ChatParseReq request;
|
private ChatParseReq request;
|
||||||
private ParseResp response;
|
private ParseResp response;
|
||||||
private Agent agent;
|
private Agent agent;
|
||||||
|
private SemanticParseInfo selectedParseInfo;
|
||||||
|
|
||||||
public ParseContext(ChatParseReq request) {
|
public ParseContext(ChatParseReq request) {
|
||||||
this.request = request;
|
this.request = request;
|
||||||
@@ -17,9 +21,14 @@ public class ParseContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean enableNL2SQL() {
|
public boolean enableNL2SQL() {
|
||||||
if (agent == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return agent.containsDatasetTool();
|
return agent.containsDatasetTool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean enableFeedback() {
|
||||||
|
return agent.enableFeedback() && Objects.isNull(request.getParseId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean enableLLM() {
|
||||||
|
return !(enableFeedback() || request.isDisableLLM());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,6 +168,12 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
|||||||
ParseContext parseContext = new ParseContext(chatParseReq);
|
ParseContext parseContext = new ParseContext(chatParseReq);
|
||||||
Agent agent = agentService.getAgent(chatParseReq.getAgentId());
|
Agent agent = agentService.getAgent(chatParseReq.getAgentId());
|
||||||
parseContext.setAgent(agent);
|
parseContext.setAgent(agent);
|
||||||
|
if (Objects.nonNull(chatParseReq.getQueryId())
|
||||||
|
&& Objects.nonNull(chatParseReq.getParseId())) {
|
||||||
|
SemanticParseInfo parseInfo = chatManageService.getParseInfo(chatParseReq.getQueryId(),
|
||||||
|
chatParseReq.getParseId());
|
||||||
|
parseContext.setSelectedParseInfo(parseInfo);
|
||||||
|
}
|
||||||
return parseContext;
|
return parseContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,16 +8,13 @@ import com.tencent.supersonic.headless.api.pojo.request.QueryNLReq;
|
|||||||
public class QueryReqConverter {
|
public class QueryReqConverter {
|
||||||
|
|
||||||
public static QueryNLReq buildQueryNLReq(ParseContext parseContext) {
|
public static QueryNLReq buildQueryNLReq(ParseContext parseContext) {
|
||||||
if (parseContext.getAgent() == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
QueryNLReq queryNLReq = new QueryNLReq();
|
QueryNLReq queryNLReq = new QueryNLReq();
|
||||||
BeanMapper.mapper(parseContext.getRequest(), queryNLReq);
|
BeanMapper.mapper(parseContext.getRequest(), queryNLReq);
|
||||||
queryNLReq.setText2SQLType(parseContext.getRequest().isDisableLLM() ? Text2SQLType.ONLY_RULE
|
queryNLReq.setText2SQLType(
|
||||||
: Text2SQLType.RULE_AND_LLM);
|
parseContext.enableLLM() ? Text2SQLType.RULE_AND_LLM : Text2SQLType.ONLY_RULE);
|
||||||
queryNLReq.setDataSetIds(parseContext.getAgent().getDataSetIds());
|
queryNLReq.setDataSetIds(parseContext.getAgent().getDataSetIds());
|
||||||
queryNLReq.setChatAppConfig(parseContext.getAgent().getChatAppConfig());
|
queryNLReq.setChatAppConfig(parseContext.getAgent().getChatAppConfig());
|
||||||
|
queryNLReq.setSelectedParseInfo(parseContext.getSelectedParseInfo());
|
||||||
|
|
||||||
return queryNLReq;
|
return queryNLReq;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ public class SchemaMapInfo {
|
|||||||
|
|
||||||
private final Map<Long, List<SchemaElementMatch>> dataSetElementMatches = new HashMap<>();
|
private final Map<Long, List<SchemaElementMatch>> dataSetElementMatches = new HashMap<>();
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return dataSetElementMatches.keySet().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
public Set<Long> getMatchedDataSetInfos() {
|
public Set<Long> getMatchedDataSetInfos() {
|
||||||
return dataSetElementMatches.keySet();
|
return dataSetElementMatches.keySet();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public class QueryNLReq extends SemanticQueryReq {
|
|||||||
private Map<String, ChatApp> chatAppConfig;
|
private Map<String, ChatApp> chatAppConfig;
|
||||||
private List<Text2SQLExemplar> dynamicExemplars = Lists.newArrayList();
|
private List<Text2SQLExemplar> dynamicExemplars = Lists.newArrayList();
|
||||||
private SemanticParseInfo contextParseInfo;
|
private SemanticParseInfo contextParseInfo;
|
||||||
|
private SemanticParseInfo selectedParseInfo;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toCustomizedString() {
|
public String toCustomizedString() {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
|||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
import com.tencent.supersonic.headless.api.pojo.DataSetSchema;
|
import com.tencent.supersonic.headless.api.pojo.DataSetSchema;
|
||||||
import com.tencent.supersonic.headless.api.pojo.SchemaMapInfo;
|
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.SemanticSchema;
|
||||||
import com.tencent.supersonic.headless.api.pojo.enums.ChatWorkflowState;
|
import com.tencent.supersonic.headless.api.pojo.enums.ChatWorkflowState;
|
||||||
import com.tencent.supersonic.headless.api.pojo.request.QueryNLReq;
|
import com.tencent.supersonic.headless.api.pojo.request.QueryNLReq;
|
||||||
@@ -15,6 +16,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@@ -35,6 +37,10 @@ public class ChatQueryContext {
|
|||||||
|
|
||||||
public ChatQueryContext(QueryNLReq request) {
|
public ChatQueryContext(QueryNLReq request) {
|
||||||
this.request = 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() {
|
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.SemanticSchema;
|
||||||
import com.tencent.supersonic.headless.api.pojo.SqlEvaluation;
|
import com.tencent.supersonic.headless.api.pojo.SqlEvaluation;
|
||||||
import com.tencent.supersonic.headless.api.pojo.SqlInfo;
|
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.QueryMapReq;
|
||||||
import com.tencent.supersonic.headless.api.pojo.request.QueryNLReq;
|
import com.tencent.supersonic.headless.api.pojo.request.QueryNLReq;
|
||||||
import com.tencent.supersonic.headless.api.pojo.request.QuerySqlReq;
|
import com.tencent.supersonic.headless.api.pojo.request.QuerySqlReq;
|
||||||
@@ -87,7 +88,11 @@ public class S2ChatLayerService implements ChatLayerService {
|
|||||||
public ParseResp parse(QueryNLReq queryNLReq) {
|
public ParseResp parse(QueryNLReq queryNLReq) {
|
||||||
ParseResp parseResult = new ParseResp(queryNLReq.getQueryText());
|
ParseResp parseResult = new ParseResp(queryNLReq.getQueryText());
|
||||||
ChatQueryContext queryCtx = buildChatQueryContext(queryNLReq);
|
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;
|
return parseResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,6 +118,7 @@ public class S2ChatLayerService implements ChatLayerService {
|
|||||||
Map<Long, List<Long>> modelIdToDataSetIds = dataSetService.getModelIdToDataSetIds();
|
Map<Long, List<Long>> modelIdToDataSetIds = dataSetService.getModelIdToDataSetIds();
|
||||||
queryCtx.setSemanticSchema(semanticSchema);
|
queryCtx.setSemanticSchema(semanticSchema);
|
||||||
queryCtx.setModelIdToDataSetIds(modelIdToDataSetIds);
|
queryCtx.setModelIdToDataSetIds(modelIdToDataSetIds);
|
||||||
|
|
||||||
return queryCtx;
|
return queryCtx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,13 +36,14 @@ public class ChatWorkflowEngine {
|
|||||||
ComponentFactory.getSemanticCorrectors();
|
ComponentFactory.getSemanticCorrectors();
|
||||||
private final List<ResultProcessor> resultProcessors = ComponentFactory.getResultProcessors();
|
private final List<ResultProcessor> resultProcessors = ComponentFactory.getResultProcessors();
|
||||||
|
|
||||||
public void start(ChatQueryContext queryCtx, ParseResp parseResult) {
|
public void start(ChatWorkflowState initialState, ChatQueryContext queryCtx,
|
||||||
queryCtx.setChatWorkflowState(ChatWorkflowState.MAPPING);
|
ParseResp parseResult) {
|
||||||
|
queryCtx.setChatWorkflowState(initialState);
|
||||||
while (queryCtx.getChatWorkflowState() != ChatWorkflowState.FINISHED) {
|
while (queryCtx.getChatWorkflowState() != ChatWorkflowState.FINISHED) {
|
||||||
switch (queryCtx.getChatWorkflowState()) {
|
switch (queryCtx.getChatWorkflowState()) {
|
||||||
case MAPPING:
|
case MAPPING:
|
||||||
performMapping(queryCtx);
|
performMapping(queryCtx);
|
||||||
if (queryCtx.getMapInfo().getMatchedDataSetInfos().isEmpty()) {
|
if (queryCtx.getMapInfo().isEmpty()) {
|
||||||
parseResult.setState(ParseResp.ParseState.FAILED);
|
parseResult.setState(ParseResp.ParseState.FAILED);
|
||||||
parseResult.setErrorMsg(
|
parseResult.setErrorMsg(
|
||||||
"No semantic entities can be mapped against user question.");
|
"No semantic entities can be mapped against user question.");
|
||||||
|
|||||||
Reference in New Issue
Block a user