mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 12:37:55 +00:00
[improvement][headless-chat]Rename methods of ChatQuery and ChatLayer service.
This commit is contained in:
@@ -89,7 +89,7 @@ public class NL2SQLParser implements ChatQueryParser {
|
|||||||
addDynamicExemplars(parseContext.getAgent().getId(), queryNLReq);
|
addDynamicExemplars(parseContext.getAgent().getId(), queryNLReq);
|
||||||
|
|
||||||
ChatLayerService chatLayerService = ContextUtils.getBean(ChatLayerService.class);
|
ChatLayerService chatLayerService = ContextUtils.getBean(ChatLayerService.class);
|
||||||
ParseResp text2SqlParseResp = chatLayerService.performParsing(queryNLReq);
|
ParseResp text2SqlParseResp = chatLayerService.parse(queryNLReq);
|
||||||
if (ParseResp.ParseState.COMPLETED.equals(text2SqlParseResp.getState())) {
|
if (ParseResp.ParseState.COMPLETED.equals(text2SqlParseResp.getState())) {
|
||||||
parseResp.getSelectedParses().addAll(text2SqlParseResp.getSelectedParses());
|
parseResp.getSelectedParses().addAll(text2SqlParseResp.getSelectedParses());
|
||||||
} else {
|
} else {
|
||||||
@@ -176,7 +176,7 @@ 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.buildText2SqlQueryReq(parseContext);
|
QueryNLReq queryNLReq = QueryReqConverter.buildText2SqlQueryReq(parseContext);
|
||||||
MapResp currentMapResult = chatLayerService.performMapping(queryNLReq);
|
MapResp currentMapResult = chatLayerService.map(queryNLReq);
|
||||||
|
|
||||||
List<QueryResp> historyQueries = getHistoryQueries(parseContext.getChatId(), 1);
|
List<QueryResp> historyQueries = getHistoryQueries(parseContext.getChatId(), 1);
|
||||||
if (historyQueries.size() == 0) {
|
if (historyQueries.size() == 0) {
|
||||||
@@ -206,7 +206,7 @@ public class NL2SQLParser implements ChatQueryParser {
|
|||||||
keyPipelineLog.info("NL2SQLParser modelResp:{}", rewrittenQuery);
|
keyPipelineLog.info("NL2SQLParser modelResp:{}", rewrittenQuery);
|
||||||
parseContext.setQueryText(rewrittenQuery);
|
parseContext.setQueryText(rewrittenQuery);
|
||||||
QueryNLReq rewrittenQueryNLReq = QueryReqConverter.buildText2SqlQueryReq(parseContext);
|
QueryNLReq rewrittenQueryNLReq = QueryReqConverter.buildText2SqlQueryReq(parseContext);
|
||||||
MapResp rewrittenQueryMapResult = chatLayerService.performMapping(rewrittenQueryNLReq);
|
MapResp rewrittenQueryMapResult = chatLayerService.map(rewrittenQueryNLReq);
|
||||||
parseContext.setMapInfo(rewrittenQueryMapResult.getMapInfo());
|
parseContext.setMapInfo(rewrittenQueryMapResult.getMapInfo());
|
||||||
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);
|
||||||
|
|||||||
@@ -41,14 +41,14 @@ public class ChatQueryController {
|
|||||||
public Object parse(@RequestBody ChatParseReq chatParseReq, HttpServletRequest request,
|
public Object parse(@RequestBody ChatParseReq chatParseReq, HttpServletRequest request,
|
||||||
HttpServletResponse response) throws Exception {
|
HttpServletResponse response) throws Exception {
|
||||||
chatParseReq.setUser(UserHolder.findUser(request, response));
|
chatParseReq.setUser(UserHolder.findUser(request, response));
|
||||||
return chatQueryService.performParsing(chatParseReq);
|
return chatQueryService.parse(chatParseReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("execute")
|
@PostMapping("execute")
|
||||||
public Object execute(@RequestBody ChatExecuteReq chatExecuteReq, HttpServletRequest request,
|
public Object execute(@RequestBody ChatExecuteReq chatExecuteReq, HttpServletRequest request,
|
||||||
HttpServletResponse response) throws Exception {
|
HttpServletResponse response) throws Exception {
|
||||||
chatExecuteReq.setUser(UserHolder.findUser(request, response));
|
chatExecuteReq.setUser(UserHolder.findUser(request, response));
|
||||||
return chatQueryService.performExecution(chatExecuteReq);
|
return chatQueryService.execute(chatExecuteReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/")
|
@PostMapping("/")
|
||||||
@@ -56,7 +56,7 @@ public class ChatQueryController {
|
|||||||
HttpServletResponse response) throws Exception {
|
HttpServletResponse response) throws Exception {
|
||||||
User user = UserHolder.findUser(request, response);
|
User user = UserHolder.findUser(request, response);
|
||||||
chatParseReq.setUser(user);
|
chatParseReq.setUser(user);
|
||||||
ParseResp parseResp = chatQueryService.performParsing(chatParseReq);
|
ParseResp parseResp = chatQueryService.parse(chatParseReq);
|
||||||
|
|
||||||
if (CollectionUtils.isEmpty(parseResp.getSelectedParses())) {
|
if (CollectionUtils.isEmpty(parseResp.getSelectedParses())) {
|
||||||
throw new InvalidArgumentException("parser error,no selectedParses");
|
throw new InvalidArgumentException("parser error,no selectedParses");
|
||||||
@@ -66,7 +66,7 @@ public class ChatQueryController {
|
|||||||
BeanUtils.copyProperties(chatParseReq, chatExecuteReq);
|
BeanUtils.copyProperties(chatParseReq, chatExecuteReq);
|
||||||
chatExecuteReq.setQueryId(parseResp.getQueryId());
|
chatExecuteReq.setQueryId(parseResp.getQueryId());
|
||||||
chatExecuteReq.setParseId(semanticParseInfo.getId());
|
chatExecuteReq.setParseId(semanticParseInfo.getId());
|
||||||
return chatQueryService.performExecution(chatExecuteReq);
|
return chatQueryService.execute(chatExecuteReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("queryData")
|
@PostMapping("queryData")
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ public interface ChatQueryService {
|
|||||||
|
|
||||||
List<SearchResult> search(ChatParseReq chatParseReq);
|
List<SearchResult> search(ChatParseReq chatParseReq);
|
||||||
|
|
||||||
ParseResp performParsing(ChatParseReq chatParseReq);
|
ParseResp parse(ChatParseReq chatParseReq);
|
||||||
|
|
||||||
QueryResult performExecution(ChatExecuteReq chatExecuteReq) throws Exception;
|
QueryResult execute(ChatExecuteReq chatExecuteReq) throws Exception;
|
||||||
|
|
||||||
QueryResult parseAndExecute(ChatParseReq chatParseReq);
|
QueryResult parseAndExecute(ChatParseReq chatParseReq);
|
||||||
|
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ParseResp performParsing(ChatParseReq chatParseReq) {
|
public ParseResp parse(ChatParseReq chatParseReq) {
|
||||||
ParseResp parseResp = new ParseResp(chatParseReq.getQueryText());
|
ParseResp parseResp = new ParseResp(chatParseReq.getQueryText());
|
||||||
chatManageService.createChatQuery(chatParseReq, parseResp);
|
chatManageService.createChatQuery(chatParseReq, parseResp);
|
||||||
ParseContext parseContext = buildParseContext(chatParseReq);
|
ParseContext parseContext = buildParseContext(chatParseReq);
|
||||||
@@ -124,7 +124,7 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryResult performExecution(ChatExecuteReq chatExecuteReq) {
|
public QueryResult execute(ChatExecuteReq chatExecuteReq) {
|
||||||
QueryResult queryResult = new QueryResult();
|
QueryResult queryResult = new QueryResult();
|
||||||
ExecuteContext executeContext = buildExecuteContext(chatExecuteReq);
|
ExecuteContext executeContext = buildExecuteContext(chatExecuteReq);
|
||||||
for (ChatQueryExecutor chatQueryExecutor : chatQueryExecutors) {
|
for (ChatQueryExecutor chatQueryExecutor : chatQueryExecutors) {
|
||||||
@@ -146,7 +146,7 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryResult parseAndExecute(ChatParseReq chatParseReq) {
|
public QueryResult parseAndExecute(ChatParseReq chatParseReq) {
|
||||||
ParseResp parseResp = performParsing(chatParseReq);
|
ParseResp parseResp = parse(chatParseReq);
|
||||||
if (CollectionUtils.isEmpty(parseResp.getSelectedParses())) {
|
if (CollectionUtils.isEmpty(parseResp.getSelectedParses())) {
|
||||||
log.debug("chatId:{}, agentId:{}, queryText:{}, parseResp.getSelectedParses() is empty",
|
log.debug("chatId:{}, agentId:{}, queryText:{}, parseResp.getSelectedParses() is empty",
|
||||||
chatParseReq.getChatId(), chatParseReq.getAgentId(),
|
chatParseReq.getChatId(), chatParseReq.getAgentId(),
|
||||||
@@ -161,7 +161,7 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
|||||||
executeReq.setUser(User.getFakeUser());
|
executeReq.setUser(User.getFakeUser());
|
||||||
executeReq.setAgentId(chatParseReq.getAgentId());
|
executeReq.setAgentId(chatParseReq.getAgentId());
|
||||||
executeReq.setSaveAnswer(true);
|
executeReq.setSaveAnswer(true);
|
||||||
return performExecution(executeReq);
|
return execute(executeReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ParseContext buildParseContext(ChatParseReq chatParseReq) {
|
private ParseContext buildParseContext(ChatParseReq chatParseReq) {
|
||||||
@@ -174,7 +174,7 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
|||||||
|
|
||||||
private void supplyMapInfo(ParseContext parseContext) {
|
private void supplyMapInfo(ParseContext parseContext) {
|
||||||
QueryNLReq queryNLReq = QueryReqConverter.buildText2SqlQueryReq(parseContext);
|
QueryNLReq queryNLReq = QueryReqConverter.buildText2SqlQueryReq(parseContext);
|
||||||
MapResp mapResp = chatLayerService.performMapping(queryNLReq);
|
MapResp mapResp = chatLayerService.map(queryNLReq);
|
||||||
parseContext.setMapInfo(mapResp.getMapInfo());
|
parseContext.setMapInfo(mapResp.getMapInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,21 +40,21 @@ public class ChatQueryApiController {
|
|||||||
public Object map(@RequestBody QueryNLReq queryNLReq, HttpServletRequest request,
|
public Object map(@RequestBody QueryNLReq queryNLReq, HttpServletRequest request,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
queryNLReq.setUser(UserHolder.findUser(request, response));
|
queryNLReq.setUser(UserHolder.findUser(request, response));
|
||||||
return chatLayerService.performMapping(queryNLReq);
|
return chatLayerService.map(queryNLReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/chat/parse")
|
@PostMapping("/chat/parse")
|
||||||
public Object parse(@RequestBody QueryNLReq queryNLReq, HttpServletRequest request,
|
public Object parse(@RequestBody QueryNLReq queryNLReq, HttpServletRequest request,
|
||||||
HttpServletResponse response) throws Exception {
|
HttpServletResponse response) throws Exception {
|
||||||
queryNLReq.setUser(UserHolder.findUser(request, response));
|
queryNLReq.setUser(UserHolder.findUser(request, response));
|
||||||
return chatLayerService.performParsing(queryNLReq);
|
return chatLayerService.parse(queryNLReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/chat")
|
@PostMapping("/chat")
|
||||||
public Object queryByNL(@RequestBody QueryNLReq queryNLReq, HttpServletRequest request,
|
public Object queryByNL(@RequestBody QueryNLReq queryNLReq, HttpServletRequest request,
|
||||||
HttpServletResponse response) throws Exception {
|
HttpServletResponse response) throws Exception {
|
||||||
User user = UserHolder.findUser(request, response);
|
User user = UserHolder.findUser(request, response);
|
||||||
ParseResp parseResp = chatLayerService.performParsing(queryNLReq);
|
ParseResp parseResp = chatLayerService.parse(queryNLReq);
|
||||||
if (parseResp.getState().equals(ParseResp.ParseState.COMPLETED)) {
|
if (parseResp.getState().equals(ParseResp.ParseState.COMPLETED)) {
|
||||||
SemanticParseInfo parseInfo = parseResp.getSelectedParses().get(0);
|
SemanticParseInfo parseInfo = parseResp.getSelectedParses().get(0);
|
||||||
QuerySqlReq sqlReq = new QuerySqlReq();
|
QuerySqlReq sqlReq = new QuerySqlReq();
|
||||||
|
|||||||
@@ -15,14 +15,14 @@ import java.util.List;
|
|||||||
/** This interface adds natural language support to the semantic layer. */
|
/** This interface adds natural language support to the semantic layer. */
|
||||||
public interface ChatLayerService {
|
public interface ChatLayerService {
|
||||||
|
|
||||||
MapResp performMapping(QueryNLReq queryNLReq);
|
MapResp map(QueryNLReq queryNLReq);
|
||||||
|
|
||||||
ParseResp performParsing(QueryNLReq queryNLReq);
|
|
||||||
|
|
||||||
MapInfoResp map(QueryMapReq queryMapReq);
|
MapInfoResp map(QueryMapReq queryMapReq);
|
||||||
|
|
||||||
List<SearchResult> retrieve(QueryNLReq queryNLReq);
|
List<SearchResult> retrieve(QueryNLReq queryNLReq);
|
||||||
|
|
||||||
|
ParseResp parse(QueryNLReq queryNLReq);
|
||||||
|
|
||||||
void correct(QuerySqlReq querySqlReq, User user);
|
void correct(QuerySqlReq querySqlReq, User user);
|
||||||
|
|
||||||
SqlEvaluation validate(QuerySqlReq querySqlReq, User user);
|
SqlEvaluation validate(QuerySqlReq querySqlReq, User user);
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class S2ChatLayerService implements ChatLayerService {
|
|||||||
private ChatWorkflowEngine chatWorkflowEngine;
|
private ChatWorkflowEngine chatWorkflowEngine;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapResp performMapping(QueryNLReq queryNLReq) {
|
public MapResp map(QueryNLReq queryNLReq) {
|
||||||
MapResp mapResp = new MapResp(queryNLReq.getQueryText());
|
MapResp mapResp = new MapResp(queryNLReq.getQueryText());
|
||||||
ChatQueryContext queryCtx = buildChatQueryContext(queryNLReq);
|
ChatQueryContext queryCtx = buildChatQueryContext(queryNLReq);
|
||||||
ComponentFactory.getSchemaMappers().forEach(mapper -> {
|
ComponentFactory.getSchemaMappers().forEach(mapper -> {
|
||||||
@@ -82,13 +82,13 @@ public class S2ChatLayerService implements ChatLayerService {
|
|||||||
|
|
||||||
Set<Long> dataSetIds = dataSets.stream().map(SchemaItem::getId).collect(Collectors.toSet());
|
Set<Long> dataSetIds = dataSets.stream().map(SchemaItem::getId).collect(Collectors.toSet());
|
||||||
queryNLReq.setDataSetIds(dataSetIds);
|
queryNLReq.setDataSetIds(dataSetIds);
|
||||||
MapResp mapResp = performMapping(queryNLReq);
|
MapResp mapResp = map(queryNLReq);
|
||||||
dataSetIds.retainAll(mapResp.getMapInfo().getDataSetElementMatches().keySet());
|
dataSetIds.retainAll(mapResp.getMapInfo().getDataSetElementMatches().keySet());
|
||||||
return convert(mapResp, queryMapReq.getTopN(), dataSetIds);
|
return convert(mapResp, queryMapReq.getTopN(), dataSetIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ParseResp performParsing(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.execute(queryCtx, parseResult);
|
chatWorkflowEngine.execute(queryCtx, parseResult);
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class BaseTest extends BaseApplication {
|
|||||||
ChatExecuteReq request = ChatExecuteReq.builder().queryText(parseResp.getQueryText())
|
ChatExecuteReq request = ChatExecuteReq.builder().queryText(parseResp.getQueryText())
|
||||||
.user(DataUtils.getUser()).parseId(semanticParseInfo.getId())
|
.user(DataUtils.getUser()).parseId(semanticParseInfo.getId())
|
||||||
.queryId(parseResp.getQueryId()).chatId(chatId).saveAnswer(true).build();
|
.queryId(parseResp.getQueryId()).chatId(chatId).saveAnswer(true).build();
|
||||||
QueryResult queryResult = chatQueryService.performExecution(request);
|
QueryResult queryResult = chatQueryService.execute(request);
|
||||||
queryResult.setChatContext(semanticParseInfo);
|
queryResult.setChatContext(semanticParseInfo);
|
||||||
return queryResult;
|
return queryResult;
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ public class BaseTest extends BaseApplication {
|
|||||||
.user(DataUtils.getUser()).parseId(parseInfo.getId()).agentId(agentId)
|
.user(DataUtils.getUser()).parseId(parseInfo.getId()).agentId(agentId)
|
||||||
.chatId(chatId).queryId(parseResp.getQueryId()).saveAnswer(false).build();
|
.chatId(chatId).queryId(parseResp.getQueryId()).saveAnswer(false).build();
|
||||||
|
|
||||||
QueryResult result = chatQueryService.performExecution(request);
|
QueryResult result = chatQueryService.execute(request);
|
||||||
result.setChatContext(parseInfo);
|
result.setChatContext(parseInfo);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ public class BaseTest extends BaseApplication {
|
|||||||
protected ParseResp submitParse(String queryText, Integer agentId, Integer chatId) {
|
protected ParseResp submitParse(String queryText, Integer agentId, Integer chatId) {
|
||||||
ChatParseReq chatParseReq = DataUtils.getChatParseReq(chatId, queryText);
|
ChatParseReq chatParseReq = DataUtils.getChatParseReq(chatId, queryText);
|
||||||
chatParseReq.setAgentId(agentId);
|
chatParseReq.setAgentId(agentId);
|
||||||
return chatQueryService.performParsing(chatParseReq);
|
return chatQueryService.parse(chatParseReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertSchemaElements(Set<SchemaElement> expected, Set<SchemaElement> actual) {
|
protected void assertSchemaElements(Set<SchemaElement> expected, Set<SchemaElement> actual) {
|
||||||
|
|||||||
Reference in New Issue
Block a user