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