Skip to content

Commit

Permalink
(improvement)(chat) Fix agent filter rule query
Browse files Browse the repository at this point in the history
  • Loading branch information
jolunoluo committed Feb 29, 2024
1 parent 895f38b commit 925cda9
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,22 @@ public class AgentCheckParser implements SemanticParser {
@Override
public void parse(QueryContext queryContext, ChatContext chatContext) {
List<SemanticQuery> queries = queryContext.getCandidateQueries();
agentCanSupport(queryContext, queries);
log.info("query size before agent filter:{}", queryContext.getCandidateQueries().size());
filterQueries(queryContext, queries);
log.info("query size after agent filter: {}", queryContext.getCandidateQueries().size());
}

private void agentCanSupport(QueryContext queryContext, List<SemanticQuery> queries) {
private void filterQueries(QueryContext queryContext, List<SemanticQuery> queries) {
Agent agent = queryContext.getAgent();
if (agent == null) {
return;
}
List<RuleParserTool> queryTools = getRuleTools(agent);
if (CollectionUtils.isEmpty(queryTools)) {
queries.clear();
queryContext.setCandidateQueries(Lists.newArrayList());
return;
}
log.info("queries resolved:{} {}", agent.getName(),
log.info("agent name :{}, queries resolved: {}", agent.getName(),
queries.stream().map(SemanticQuery::getQueryMode).collect(Collectors.toList()));
queries.removeIf(query -> {
for (RuleParserTool tool : queryTools) {
Expand All @@ -46,10 +48,14 @@ private void agentCanSupport(QueryContext queryContext, List<SemanticQuery> quer
}
if (CollectionUtils.isNotEmpty(tool.getQueryTypes())) {
if (QueryManager.isTagQuery(query.getQueryMode())) {
return !tool.getQueryTypes().contains(QueryType.TAG.name());
if (!tool.getQueryTypes().contains(QueryType.TAG.name())) {
return true;
}
}
if (QueryManager.isMetricQuery(query.getQueryMode())) {
return !tool.getQueryTypes().contains(QueryType.METRIC.name());
if (!tool.getQueryTypes().contains(QueryType.METRIC.name())) {
return true;
}
}
}
if (CollectionUtils.isEmpty(tool.getViewIds())) {
Expand All @@ -62,7 +68,8 @@ private void agentCanSupport(QueryContext queryContext, List<SemanticQuery> quer
}
return true;
});
log.info("rule queries witch can be supported by agent :{} {}", agent.getName(),
queryContext.setCandidateQueries(queries);
log.info("agent name :{}, rule queries witch can be supported by agent :{}", agent.getName(),
queries.stream().map(SemanticQuery::getQueryMode).collect(Collectors.toList()));
}

Expand Down

0 comments on commit 925cda9

Please sign in to comment.