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