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