mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 11:07:06 +00:00
[improvement][headless-chat]Demo queries only use rule-based parser.
This commit is contained in:
@@ -3,9 +3,15 @@ package com.tencent.supersonic.chat.api.pojo.request;
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.headless.api.pojo.SchemaMapInfo;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.QueryFilters;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class ChatParseReq {
|
||||
private String queryText;
|
||||
private Integer chatId;
|
||||
@@ -15,4 +21,5 @@ public class ChatParseReq {
|
||||
private QueryFilters queryFilters;
|
||||
private boolean saveAnswer = true;
|
||||
private SchemaMapInfo mapInfo = new SchemaMapInfo();
|
||||
private boolean disableLLM = false;
|
||||
}
|
||||
|
||||
@@ -15,17 +15,18 @@ public class ParseContext {
|
||||
private QueryFilters queryFilters;
|
||||
private boolean saveAnswer = true;
|
||||
private SchemaMapInfo mapInfo;
|
||||
private boolean disableLLM = false;
|
||||
|
||||
public boolean enableNL2SQL() {
|
||||
if (agent == null) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
return agent.containsNL2SQLTool();
|
||||
}
|
||||
|
||||
public boolean enbaleLLM() {
|
||||
if (agent == null) {
|
||||
return true;
|
||||
if (agent == null || disableLLM) {
|
||||
return false;
|
||||
}
|
||||
return agent.containsLLMTool();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public interface ChatQueryService {
|
||||
|
||||
QueryResult performExecution(ChatExecuteReq chatExecuteReq) throws Exception;
|
||||
|
||||
QueryResult parseAndExecute(int chatId, int agentId, String queryText);
|
||||
QueryResult parseAndExecute(ChatParseReq chatParseReq);
|
||||
|
||||
Object queryData(ChatQueryDataReq chatQueryDataReq, User user) throws Exception;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.tencent.supersonic.chat.server.service.impl;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.chat.api.pojo.request.ChatMemoryFilter;
|
||||
import com.tencent.supersonic.chat.api.pojo.request.ChatParseReq;
|
||||
import com.tencent.supersonic.chat.server.agent.Agent;
|
||||
import com.tencent.supersonic.chat.server.agent.MultiTurnConfig;
|
||||
import com.tencent.supersonic.chat.server.persistence.dataobject.AgentDO;
|
||||
@@ -115,7 +116,8 @@ public class AgentServiceImpl extends ServiceImpl<AgentDOMapper, AgentDO> implem
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
chatQueryService.parseAndExecute(-1, agent.getId(), example);
|
||||
chatQueryService.parseAndExecute(ChatParseReq.builder().chatId(-1)
|
||||
.agentId(agent.getId()).queryText(example).build());
|
||||
} catch (Exception e) {
|
||||
log.warn("agent:{} example execute failed:{}", agent.getName(), example);
|
||||
}
|
||||
|
||||
@@ -145,25 +145,21 @@ public class ChatQueryServiceImpl implements ChatQueryService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryResult parseAndExecute(int chatId, int agentId, String queryText) {
|
||||
ChatParseReq chatParseReq = new ChatParseReq();
|
||||
chatParseReq.setQueryText(queryText);
|
||||
chatParseReq.setChatId(chatId);
|
||||
chatParseReq.setAgentId(agentId);
|
||||
chatParseReq.setUser(User.getFakeUser());
|
||||
public QueryResult parseAndExecute(ChatParseReq chatParseReq) {
|
||||
ParseResp parseResp = performParsing(chatParseReq);
|
||||
if (CollectionUtils.isEmpty(parseResp.getSelectedParses())) {
|
||||
log.debug("chatId:{}, agentId:{}, queryText:{}, parseResp.getSelectedParses() is empty",
|
||||
chatId, agentId, queryText);
|
||||
chatParseReq.getChatId(), chatParseReq.getAgentId(),
|
||||
chatParseReq.getQueryText());
|
||||
return null;
|
||||
}
|
||||
ChatExecuteReq executeReq = new ChatExecuteReq();
|
||||
executeReq.setQueryId(parseResp.getQueryId());
|
||||
executeReq.setParseId(parseResp.getSelectedParses().get(0).getId());
|
||||
executeReq.setQueryText(queryText);
|
||||
executeReq.setChatId(chatId);
|
||||
executeReq.setQueryText(chatParseReq.getQueryText());
|
||||
executeReq.setChatId(chatParseReq.getChatId());
|
||||
executeReq.setUser(User.getFakeUser());
|
||||
executeReq.setAgentId(agentId);
|
||||
executeReq.setAgentId(chatParseReq.getAgentId());
|
||||
executeReq.setSaveAnswer(true);
|
||||
return performExecution(executeReq);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,9 @@ public class QueryReqConverter {
|
||||
boolean hasRuleTool = agent.containsRuleTool();
|
||||
boolean hasLLMConfig = Objects.nonNull(agent.getModelConfig());
|
||||
|
||||
if (hasLLMTool && hasLLMConfig) {
|
||||
if (parseContext.isDisableLLM()) {
|
||||
queryNLReq.setText2SQLType(Text2SQLType.ONLY_RULE);
|
||||
} else if (hasLLMTool && hasLLMConfig) {
|
||||
queryNLReq.setText2SQLType(Text2SQLType.ONLY_LLM);
|
||||
} else if (hasLLMTool && hasRuleTool) {
|
||||
queryNLReq.setText2SQLType(Text2SQLType.RULE_AND_LLM);
|
||||
@@ -37,6 +39,7 @@ public class QueryReqConverter {
|
||||
} else if (hasRuleTool) {
|
||||
queryNLReq.setText2SQLType(Text2SQLType.ONLY_RULE);
|
||||
}
|
||||
|
||||
queryNLReq.setDataSetIds(agent.getDataSetIds());
|
||||
if (Objects.nonNull(queryNLReq.getMapInfo())
|
||||
&& MapUtils.isNotEmpty(queryNLReq.getMapInfo().getDataSetElementMatches())) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.google.common.collect.Lists;
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.auth.api.authorization.pojo.AuthGroup;
|
||||
import com.tencent.supersonic.auth.api.authorization.pojo.AuthRule;
|
||||
import com.tencent.supersonic.chat.api.pojo.request.ChatParseReq;
|
||||
import com.tencent.supersonic.chat.server.agent.Agent;
|
||||
import com.tencent.supersonic.chat.server.agent.AgentConfig;
|
||||
import com.tencent.supersonic.chat.server.agent.AgentToolType;
|
||||
@@ -136,12 +137,16 @@ public class S2VisitsDemo extends S2BaseDemo {
|
||||
|
||||
public void addSampleChats(Integer agentId) {
|
||||
Long chatId = chatManageService.addChat(user, "样例对话1", agentId);
|
||||
submitText(chatId.intValue(), agentId, "超音数 访问次数");
|
||||
submitText(chatId.intValue(), agentId, "按部门统计");
|
||||
submitText(chatId.intValue(), agentId, "查询近30天");
|
||||
submitText(chatId.intValue(), agentId, "alice 停留时长");
|
||||
submitText(chatId.intValue(), agentId, "访问次数最高的部门");
|
||||
}
|
||||
|
||||
chatQueryService.parseAndExecute(chatId.intValue(), agentId, "超音数 访问次数");
|
||||
chatQueryService.parseAndExecute(chatId.intValue(), agentId, "按部门统计");
|
||||
chatQueryService.parseAndExecute(chatId.intValue(), agentId, "查询近30天");
|
||||
chatQueryService.parseAndExecute(chatId.intValue(), agentId, "alice 停留时长");
|
||||
chatQueryService.parseAndExecute(chatId.intValue(), agentId, "访问次数最高的部门");
|
||||
private void submitText(int chatId, int agentId, String queryText) {
|
||||
chatQueryService.parseAndExecute(ChatParseReq.builder().chatId(chatId).agentId(agentId)
|
||||
.queryText(queryText).user(User.getFakeUser()).disableLLM(true).build());
|
||||
}
|
||||
|
||||
private Integer addAgent(long dataSetId) {
|
||||
|
||||
Reference in New Issue
Block a user