mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-11 12:07:42 +00:00
[fix][chat]Fix NPE issue.
This commit is contained in:
@@ -27,7 +27,7 @@ public class ErrorMsgRewriteProcessor implements ParseResultProcessor {
|
|||||||
|
|
||||||
private static final Logger keyPipelineLog = LoggerFactory.getLogger("keyPipeline");
|
private static final Logger keyPipelineLog = LoggerFactory.getLogger("keyPipeline");
|
||||||
|
|
||||||
public static final String APP_KEY_ERROR_MESSAGE = "REWRITE_ERROR_MESSAGE";
|
public static final String APP_KEY = "REWRITE_ERROR_MESSAGE";
|
||||||
private static final String REWRITE_ERROR_MESSAGE_INSTRUCTION = ""
|
private static final String REWRITE_ERROR_MESSAGE_INSTRUCTION = ""
|
||||||
+ "#Role: You are a data business partner who closely interacts with business people.\n"
|
+ "#Role: You are a data business partner who closely interacts with business people.\n"
|
||||||
+ "#Task: Your will be provided with user input, system output and some examples, "
|
+ "#Task: Your will be provided with user input, system output and some examples, "
|
||||||
@@ -38,7 +38,7 @@ public class ErrorMsgRewriteProcessor implements ParseResultProcessor {
|
|||||||
+ "#Examples: {{examples}}\n" + "#Response: ";
|
+ "#Examples: {{examples}}\n" + "#Response: ";
|
||||||
|
|
||||||
public ErrorMsgRewriteProcessor() {
|
public ErrorMsgRewriteProcessor() {
|
||||||
ChatAppManager.register(APP_KEY_ERROR_MESSAGE,
|
ChatAppManager.register(APP_KEY,
|
||||||
ChatApp.builder().prompt(REWRITE_ERROR_MESSAGE_INSTRUCTION).name("异常提示改写")
|
ChatApp.builder().prompt(REWRITE_ERROR_MESSAGE_INSTRUCTION).name("异常提示改写")
|
||||||
.appModule(AppModule.CHAT).description("通过大模型将异常信息改写为更友好和引导性的提示用语")
|
.appModule(AppModule.CHAT).description("通过大模型将异常信息改写为更友好和引导性的提示用语")
|
||||||
.enable(true).build());
|
.enable(true).build());
|
||||||
@@ -46,7 +46,7 @@ public class ErrorMsgRewriteProcessor implements ParseResultProcessor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(ParseContext parseContext) {
|
public boolean accept(ParseContext parseContext) {
|
||||||
ChatApp chatApp = parseContext.getAgent().getChatAppConfig().get(APP_KEY_ERROR_MESSAGE);
|
ChatApp chatApp = parseContext.getAgent().getChatAppConfig().get(APP_KEY);
|
||||||
return StringUtils.isNotBlank(parseContext.getResponse().getErrorMsg())
|
return StringUtils.isNotBlank(parseContext.getResponse().getErrorMsg())
|
||||||
&& Objects.nonNull(chatApp) && chatApp.isEnable();
|
&& Objects.nonNull(chatApp) && chatApp.isEnable();
|
||||||
}
|
}
|
||||||
@@ -54,16 +54,20 @@ public class ErrorMsgRewriteProcessor implements ParseResultProcessor {
|
|||||||
@Override
|
@Override
|
||||||
public void process(ParseContext parseContext) {
|
public void process(ParseContext parseContext) {
|
||||||
String errMsg = parseContext.getResponse().getErrorMsg();
|
String errMsg = parseContext.getResponse().getErrorMsg();
|
||||||
ChatApp chatApp = parseContext.getAgent().getChatAppConfig().get(APP_KEY_ERROR_MESSAGE);
|
ChatApp chatApp = parseContext.getAgent().getChatAppConfig().get(APP_KEY);
|
||||||
Map<String, Object> variables = new HashMap<>();
|
Map<String, Object> variables = new HashMap<>();
|
||||||
variables.put("user_question", parseContext.getRequest().getQueryText());
|
variables.put("user_question", parseContext.getRequest().getQueryText());
|
||||||
variables.put("system_message", errMsg);
|
variables.put("system_message", errMsg);
|
||||||
|
|
||||||
StringBuilder exampleStr = new StringBuilder();
|
StringBuilder exampleStr = new StringBuilder();
|
||||||
parseContext.getResponse().getUsedExemplars().forEach(e -> exampleStr.append(
|
if (parseContext.getResponse().getUsedExemplars() != null) {
|
||||||
String.format("<Question:{%s},Schema:{%s}> ", e.getQuestion(), e.getDbSchema())));
|
parseContext.getResponse().getUsedExemplars().forEach(e -> exampleStr.append(String
|
||||||
parseContext.getAgent().getExamples()
|
.format("<Question:{%s},Schema:{%s}> ", e.getQuestion(), e.getDbSchema())));
|
||||||
.forEach(e -> exampleStr.append(String.format("<Question:{%s}> ", e)));
|
}
|
||||||
|
if (parseContext.getAgent().getExamples() != null) {
|
||||||
|
parseContext.getAgent().getExamples()
|
||||||
|
.forEach(e -> exampleStr.append(String.format("<Question:{%s}> ", e)));
|
||||||
|
}
|
||||||
variables.put("examples", exampleStr);
|
variables.put("examples", exampleStr);
|
||||||
|
|
||||||
Prompt prompt = PromptTemplate.from(chatApp.getPrompt()).apply(variables);
|
Prompt prompt = PromptTemplate.from(chatApp.getPrompt()).apply(variables);
|
||||||
|
|||||||
@@ -140,7 +140,8 @@ public class QueryUtils {
|
|||||||
|| type.equalsIgnoreCase("float") || type.equalsIgnoreCase("double")
|
|| type.equalsIgnoreCase("float") || type.equalsIgnoreCase("double")
|
||||||
|| type.equalsIgnoreCase("real") || type.equalsIgnoreCase("numeric")
|
|| type.equalsIgnoreCase("real") || type.equalsIgnoreCase("numeric")
|
||||||
|| type.toLowerCase().startsWith("decimal") || type.toLowerCase().startsWith("uint")
|
|| type.toLowerCase().startsWith("decimal") || type.toLowerCase().startsWith("uint")
|
||||||
|| type.toLowerCase().startsWith("int") || type.toLowerCase().equalsIgnoreCase("decfloat");
|
|| type.toLowerCase().startsWith("int")
|
||||||
|
|| type.toLowerCase().equalsIgnoreCase("decfloat");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getName(String nameEn) {
|
private String getName(String nameEn) {
|
||||||
|
|||||||
Reference in New Issue
Block a user