mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 11:07:06 +00:00
(improvement)(chat) Modify the query types supported by agent rule-type tools to metric type and tag types (#424)
Co-authored-by: jolunoluo
This commit is contained in:
@@ -12,6 +12,8 @@ public class RuleQueryTool extends CommonAgentTool {
|
|||||||
|
|
||||||
private List<String> queryModes;
|
private List<String> queryModes;
|
||||||
|
|
||||||
|
private List<String> queryTypes;
|
||||||
|
|
||||||
public boolean isContainsAllModel() {
|
public boolean isContainsAllModel() {
|
||||||
return CollectionUtils.isNotEmpty(modelIds) && modelIds.contains(-1L);
|
return CollectionUtils.isNotEmpty(modelIds) && modelIds.contains(-1L);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ import com.tencent.supersonic.chat.api.component.SemanticParser;
|
|||||||
import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
import com.tencent.supersonic.chat.api.component.SemanticQuery;
|
||||||
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
import com.tencent.supersonic.chat.api.pojo.ChatContext;
|
||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
|
import com.tencent.supersonic.chat.query.QueryManager;
|
||||||
import com.tencent.supersonic.chat.service.AgentService;
|
import com.tencent.supersonic.chat.service.AgentService;
|
||||||
|
import com.tencent.supersonic.common.pojo.QueryType;
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
@@ -46,6 +48,14 @@ public class AgentCheckParser implements SemanticParser {
|
|||||||
&& !tool.getQueryModes().contains(query.getQueryMode())) {
|
&& !tool.getQueryModes().contains(query.getQueryMode())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (CollectionUtils.isNotEmpty(tool.getQueryTypes())) {
|
||||||
|
if (QueryManager.isTagQuery(query.getQueryMode())) {
|
||||||
|
return !tool.getQueryTypes().contains(QueryType.TAG.name());
|
||||||
|
}
|
||||||
|
if (QueryManager.isMetricQuery(query.getQueryMode())) {
|
||||||
|
return !tool.getQueryTypes().contains(QueryType.METRIC.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
if (CollectionUtils.isEmpty(tool.getModelIds())) {
|
if (CollectionUtils.isEmpty(tool.getModelIds())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public class QueryManager {
|
|||||||
return ruleQueryMap.get(queryMode) instanceof MetricSemanticQuery;
|
return ruleQueryMap.get(queryMode) instanceof MetricSemanticQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isEntityQuery(String queryMode) {
|
public static boolean isTagQuery(String queryMode) {
|
||||||
if (queryMode == null || !ruleQueryMap.containsKey(queryMode)) {
|
if (queryMode == null || !ruleQueryMap.containsKey(queryMode)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public abstract class RuleSemanticQuery extends BaseSemanticQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<SchemaElementMatch> match(List<SchemaElementMatch> candidateElementMatches,
|
public List<SchemaElementMatch> match(List<SchemaElementMatch> candidateElementMatches,
|
||||||
QueryContext queryCtx) {
|
QueryContext queryCtx) {
|
||||||
return queryMatcher.match(candidateElementMatches);
|
return queryMatcher.match(candidateElementMatches);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,8 +76,8 @@ public abstract class RuleSemanticQuery extends BaseSemanticQuery {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((QueryManager.isEntityQuery(queryParseInfo.getQueryMode())
|
if ((QueryManager.isTagQuery(queryParseInfo.getQueryMode())
|
||||||
&& QueryManager.isEntityQuery(chatParseInfo.getQueryMode()))
|
&& QueryManager.isTagQuery(chatParseInfo.getQueryMode()))
|
||||||
|| (QueryManager.isMetricQuery(queryParseInfo.getQueryMode())
|
|| (QueryManager.isMetricQuery(queryParseInfo.getQueryMode())
|
||||||
&& QueryManager.isMetricQuery(chatParseInfo.getQueryMode()))) {
|
&& QueryManager.isMetricQuery(chatParseInfo.getQueryMode()))) {
|
||||||
// inherit date info from context
|
// inherit date info from context
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class EntityInfoParseResponder implements ParseResponder {
|
|||||||
//1. set entity info
|
//1. set entity info
|
||||||
SemanticService semanticService = ContextUtils.getBean(SemanticService.class);
|
SemanticService semanticService = ContextUtils.getBean(SemanticService.class);
|
||||||
EntityInfo entityInfo = semanticService.getEntityInfo(parseInfo, queryReq.getUser());
|
EntityInfo entityInfo = semanticService.getEntityInfo(parseInfo, queryReq.getUser());
|
||||||
if (QueryManager.isEntityQuery(queryMode)
|
if (QueryManager.isTagQuery(queryMode)
|
||||||
|| QueryManager.isMetricQuery(queryMode)) {
|
|| QueryManager.isMetricQuery(queryMode)) {
|
||||||
parseInfo.setEntityInfo(entityInfo);
|
parseInfo.setEntityInfo(entityInfo);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import com.tencent.supersonic.chat.service.ChatService;
|
|||||||
import com.tencent.supersonic.chat.service.ConfigService;
|
import com.tencent.supersonic.chat.service.ConfigService;
|
||||||
import com.tencent.supersonic.chat.service.PluginService;
|
import com.tencent.supersonic.chat.service.PluginService;
|
||||||
import com.tencent.supersonic.chat.service.QueryService;
|
import com.tencent.supersonic.chat.service.QueryService;
|
||||||
|
import com.tencent.supersonic.common.pojo.QueryType;
|
||||||
import com.tencent.supersonic.common.pojo.SysParameter;
|
import com.tencent.supersonic.common.pojo.SysParameter;
|
||||||
import com.tencent.supersonic.common.service.SysParameterService;
|
import com.tencent.supersonic.common.service.SysParameterService;
|
||||||
import com.tencent.supersonic.common.util.JsonUtil;
|
import com.tencent.supersonic.common.util.JsonUtil;
|
||||||
@@ -263,10 +264,7 @@ public class ConfigureDemo implements ApplicationListener<ApplicationReadyEvent>
|
|||||||
ruleQueryTool.setType(AgentToolType.RULE);
|
ruleQueryTool.setType(AgentToolType.RULE);
|
||||||
ruleQueryTool.setId("0");
|
ruleQueryTool.setId("0");
|
||||||
ruleQueryTool.setModelIds(Lists.newArrayList(-1L));
|
ruleQueryTool.setModelIds(Lists.newArrayList(-1L));
|
||||||
ruleQueryTool.setQueryModes(Lists.newArrayList(
|
ruleQueryTool.setQueryTypes(Lists.newArrayList(QueryType.METRIC.name()));
|
||||||
"METRIC_ENTITY", "METRIC_FILTER", "METRIC_GROUPBY",
|
|
||||||
"METRIC_MODEL", "METRIC_ORDERBY"
|
|
||||||
));
|
|
||||||
agentConfig.getTools().add(ruleQueryTool);
|
agentConfig.getTools().add(ruleQueryTool);
|
||||||
|
|
||||||
LLMParserTool llmParserTool = new LLMParserTool();
|
LLMParserTool llmParserTool = new LLMParserTool();
|
||||||
@@ -292,8 +290,7 @@ public class ConfigureDemo implements ApplicationListener<ApplicationReadyEvent>
|
|||||||
ruleQueryTool.setId("0");
|
ruleQueryTool.setId("0");
|
||||||
ruleQueryTool.setType(AgentToolType.RULE);
|
ruleQueryTool.setType(AgentToolType.RULE);
|
||||||
ruleQueryTool.setModelIds(Lists.newArrayList(-1L));
|
ruleQueryTool.setModelIds(Lists.newArrayList(-1L));
|
||||||
ruleQueryTool.setQueryModes(Lists.newArrayList(
|
ruleQueryTool.setQueryTypes(Lists.newArrayList(QueryType.TAG.name()));
|
||||||
"TAG_DETAIL", "TAG_LIST_FILTER", "TAG_ID"));
|
|
||||||
agentConfig.getTools().add(ruleQueryTool);
|
agentConfig.getTools().add(ruleQueryTool);
|
||||||
|
|
||||||
LLMParserTool llmParserTool = new LLMParserTool();
|
LLMParserTool llmParserTool = new LLMParserTool();
|
||||||
|
|||||||
Reference in New Issue
Block a user