mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 20:51:48 +00:00
[improvement][chat]Make a few code restructure.
This commit is contained in:
@@ -1,16 +1,16 @@
|
|||||||
package com.tencent.supersonic.headless.api.pojo.response;
|
package com.tencent.supersonic.headless.api.pojo.response;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.tencent.supersonic.common.pojo.Text2SQLExemplar;
|
|
||||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ParseResp {
|
public class ParseResp implements Serializable {
|
||||||
private final String queryText;
|
private final String queryText;
|
||||||
private ParseState state = ParseState.PENDING;
|
private ParseState state = ParseState.PENDING;
|
||||||
private String errorMsg;
|
private String errorMsg;
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ package com.tencent.supersonic.headless.api.pojo.response;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ParseTimeCostResp {
|
public class ParseTimeCostResp implements Serializable {
|
||||||
|
|
||||||
private long parseStartTime;
|
private long parseStartTime;
|
||||||
private long parseTime;
|
private long parseTime;
|
||||||
|
|||||||
@@ -8,6 +8,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.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;
|
||||||
|
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
||||||
import com.tencent.supersonic.headless.chat.query.SemanticQuery;
|
import com.tencent.supersonic.headless.chat.query.SemanticQuery;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ import java.util.stream.Collectors;
|
|||||||
public class ChatQueryContext implements Serializable {
|
public class ChatQueryContext implements Serializable {
|
||||||
|
|
||||||
private QueryNLReq request;
|
private QueryNLReq request;
|
||||||
|
private ParseResp parseResp;
|
||||||
private Map<Long, List<Long>> modelIdToDataSetIds;
|
private Map<Long, List<Long>> modelIdToDataSetIds;
|
||||||
private List<SemanticQuery> candidateQueries = new ArrayList<>();
|
private List<SemanticQuery> candidateQueries = new ArrayList<>();
|
||||||
private SchemaMapInfo mapInfo = new SchemaMapInfo();
|
private SchemaMapInfo mapInfo = new SchemaMapInfo();
|
||||||
|
|||||||
@@ -65,14 +65,15 @@ public class S2ChatLayerService implements ChatLayerService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ParseResp parse(QueryNLReq queryNLReq) {
|
public ParseResp parse(QueryNLReq queryNLReq) {
|
||||||
ParseResp parseResult = new ParseResp(queryNLReq.getQueryText());
|
ParseResp parseResp = new ParseResp(queryNLReq.getQueryText());
|
||||||
ChatQueryContext queryCtx = buildChatQueryContext(queryNLReq);
|
ChatQueryContext queryCtx = buildChatQueryContext(queryNLReq);
|
||||||
|
queryCtx.setParseResp(parseResp);
|
||||||
if (queryCtx.getMapInfo().isEmpty()) {
|
if (queryCtx.getMapInfo().isEmpty()) {
|
||||||
chatWorkflowEngine.start(ChatWorkflowState.MAPPING, queryCtx, parseResult);
|
chatWorkflowEngine.start(ChatWorkflowState.MAPPING, queryCtx);
|
||||||
} else {
|
} else {
|
||||||
chatWorkflowEngine.start(ChatWorkflowState.PARSING, queryCtx, parseResult);
|
chatWorkflowEngine.start(ChatWorkflowState.PARSING, queryCtx);
|
||||||
}
|
}
|
||||||
return parseResult;
|
return parseResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void correct(QuerySqlReq querySqlReq, User user) {
|
public void correct(QuerySqlReq querySqlReq, User user) {
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ public class ChatWorkflowEngine {
|
|||||||
private final List<SemanticCorrector> semanticCorrectors =
|
private final List<SemanticCorrector> semanticCorrectors =
|
||||||
CoreComponentFactory.getSemanticCorrectors();
|
CoreComponentFactory.getSemanticCorrectors();
|
||||||
|
|
||||||
public void start(ChatWorkflowState initialState, ChatQueryContext queryCtx,
|
public void start(ChatWorkflowState initialState, ChatQueryContext queryCtx) {
|
||||||
ParseResp parseResult) {
|
ParseResp parseResult = queryCtx.getParseResp();
|
||||||
queryCtx.setChatWorkflowState(initialState);
|
queryCtx.setChatWorkflowState(initialState);
|
||||||
while (queryCtx.getChatWorkflowState() != ChatWorkflowState.FINISHED) {
|
while (queryCtx.getChatWorkflowState() != ChatWorkflowState.FINISHED) {
|
||||||
switch (queryCtx.getChatWorkflowState()) {
|
switch (queryCtx.getChatWorkflowState()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user