(improvement)(chat)Opt rewritten error message prompt.

This commit is contained in:
jerryjzhang
2024-07-30 09:26:18 +08:00
parent 9e4513f7ca
commit 2472ce2461

View File

@@ -67,8 +67,8 @@ public class NL2SQLParser implements ChatQueryParser {
+ "#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, "
+ "please respond shortly to teach user how to ask the right question, " + "please respond shortly to teach user how to ask the right question, "
+ "using `Examples` as references." + "by using `Examples` as references."
+ "#Rules: ALWAYS use the same language as the `Input`.\n" + "#Rules: ALWAYS respond with the same language as the `Input`.\n"
+ "#Input: {{user_question}}\n" + "#Input: {{user_question}}\n"
+ "#Output: {{system_message}}\n" + "#Output: {{system_message}}\n"
+ "#Examples: {{examples}}\n" + "#Examples: {{examples}}\n"
@@ -214,26 +214,20 @@ public class NL2SQLParser implements ChatQueryParser {
variables.put("system_message", errMsg); variables.put("system_message", errMsg);
StringBuilder exampleStr = new StringBuilder(); StringBuilder exampleStr = new StringBuilder();
if (similarExemplars.size() > 0) { similarExemplars.forEach(e ->
similarExemplars.stream().forEach(e -> exampleStr.append(String.format("<Question:{%s},Schema:{%s}> ", e.getQuestion(), e.getDbSchema())));
exampleStr.append(String.format("<Question:{%s},Schema:{%s}> ", agentExamples.forEach(e ->
e.getQuestion(), e.getDbSchema())) exampleStr.append(String.format("<Question:{%s}> ", e)));
);
} else {
agentExamples.stream().forEach(e ->
exampleStr.append(String.format("<Question:{%s}> ",
e)));
}
variables.put("examples", exampleStr); variables.put("examples", exampleStr);
Prompt prompt = PromptTemplate.from(REWRITE_ERROR_MESSAGE_INSTRUCTION).apply(variables); Prompt prompt = PromptTemplate.from(REWRITE_ERROR_MESSAGE_INSTRUCTION).apply(variables);
keyPipelineLog.info("NL2SQLParser reqPrompt:{}", prompt.text()); keyPipelineLog.info("NL2SQLParser reqPrompt:{}", prompt.text());
Response<AiMessage> response = chatLanguageModel.generate(prompt.toUserMessage()); Response<AiMessage> response = chatLanguageModel.generate(prompt.toUserMessage());
String result = response.content().text(); String rewrittenMsg = response.content().text();
keyPipelineLog.info("NL2SQLParser modelResp:{}", result); keyPipelineLog.info("NL2SQLParser modelResp:{}", rewrittenMsg);
return response.content().text(); return rewrittenMsg;
} }
private String generateSchemaPrompt(List<SchemaElementMatch> elementMatches) { private String generateSchemaPrompt(List<SchemaElementMatch> elementMatches) {