mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 03:58:14 +00:00
(improvement)(headless)Make rule-based corrector switchable.
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
package com.tencent.supersonic.headless.chat.corrector;
|
||||
|
||||
import com.tencent.supersonic.common.util.ContextUtils;
|
||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||
import com.tencent.supersonic.headless.chat.ChatQueryContext;
|
||||
import com.tencent.supersonic.headless.chat.parser.ParserConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.tencent.supersonic.headless.chat.parser.ParserConfig.PARSER_RULE_CORRECTOR_ENABLE;
|
||||
|
||||
@Slf4j
|
||||
public class RuleSqlCorrector extends BaseSemanticCorrector {
|
||||
private List<BaseSemanticCorrector> correctors;
|
||||
@@ -20,6 +24,11 @@ public class RuleSqlCorrector extends BaseSemanticCorrector {
|
||||
|
||||
@Override
|
||||
public void doCorrect(ChatQueryContext chatQueryContext, SemanticParseInfo semanticParseInfo) {
|
||||
ParserConfig parserConfig = ContextUtils.getBean(ParserConfig.class);
|
||||
if(!Boolean.parseBoolean(parserConfig.getParameterValue(PARSER_RULE_CORRECTOR_ENABLE))) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (BaseSemanticCorrector corrector : correctors) {
|
||||
corrector.correct(chatQueryContext, semanticParseInfo);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,10 @@ public class ParserConfig extends ParameterConfig {
|
||||
"ONE_PASS_SELF_CONSISTENCY: 通过投票方式一步生成sql", "list", "语义解析配置",
|
||||
Lists.newArrayList("ONE_PASS_SELF_CONSISTENCY"));
|
||||
|
||||
public static final Parameter PARSER_RULE_CORRECTOR_ENABLE =
|
||||
new Parameter("s2.parser.rule.corrector.enable", "false", "是否开启规则修正器",
|
||||
"规则修正器灵活度有限,在大模型能力足够情况下,不必强制做规则修正", "bool", "语义解析配置");
|
||||
|
||||
public static final Parameter PARSER_LINKING_VALUE_ENABLE =
|
||||
new Parameter("s2.parser.linking.value.enable", "true", "是否将Mapper探测识别到的维度值提供给大模型",
|
||||
"为了数据安全考虑, 这里可进行开关选择", "bool", "语义解析配置");
|
||||
@@ -55,7 +59,7 @@ public class ParserConfig extends ParameterConfig {
|
||||
|
||||
@Override
|
||||
public List<Parameter> getSysParameters() {
|
||||
return Lists.newArrayList(PARSER_LINKING_VALUE_ENABLE, PARSER_FEW_SHOT_NUMBER,
|
||||
return Lists.newArrayList(PARSER_LINKING_VALUE_ENABLE, PARSER_RULE_CORRECTOR_ENABLE, PARSER_FEW_SHOT_NUMBER,
|
||||
PARSER_SELF_CONSISTENCY_NUMBER, PARSER_SHOW_COUNT, PARSER_FIELDS_COUNT_THRESHOLD);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user