[improvement][project]Optimize log files and outputs.

This commit is contained in:
jerryjzhang
2024-10-18 14:17:47 +08:00
parent 55a4d5a198
commit 5c8b9a0ee1
9 changed files with 26 additions and 35 deletions

View File

@@ -29,7 +29,7 @@ public class LLMSqlCorrector extends BaseSemanticCorrector {
public static final String APP_KEY = "S2SQL_CORRECTOR";
private static final String INSTRUCTION = ""
+ "\n#Role: You are a senior data engineer experienced in writing SQL."
+ "#Role: You are a senior data engineer experienced in writing SQL."
+ "\n#Task: Your will be provided with a user question and the SQL written by a junior engineer,"
+ "please take a review and help correct it if necessary." + "\n#Rules: "
+ "\n1.ALWAYS follow the output format: `opinion=(POSITIVE|NEGATIVE),sql=(corrected sql if NEGATIVE; empty string if POSITIVE)`."
@@ -73,9 +73,8 @@ public class LLMSqlCorrector extends BaseSemanticCorrector {
AiServices.create(SemanticSqlExtractor.class, chatLanguageModel);
Prompt prompt = generatePrompt(chatQueryContext.getQueryText(), semanticParseInfo,
chatApp.getPrompt());
keyPipelineLog.info("LLMSqlCorrector reqPrompt:\n{}", prompt.text());
SemanticSql s2Sql = extractor.generateSemanticSql(prompt.toUserMessage().singleText());
keyPipelineLog.info("LLMSqlCorrector modelResp:\n{}", s2Sql);
keyPipelineLog.info("LLMSqlCorrector modelReq:\n{} \nmodelResp:\n{}", prompt.text(), s2Sql);
if ("NEGATIVE".equals(s2Sql.getOpinion()) && StringUtils.isNotBlank(s2Sql.getSql())) {
semanticParseInfo.getSqlInfo().setCorrectedS2SQL(s2Sql.getSql());
}

View File

@@ -15,6 +15,8 @@ import dev.langchain4j.service.AiServices;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.HashMap;
@@ -26,9 +28,11 @@ import java.util.concurrent.ConcurrentHashMap;
@Slf4j
public class OnePassSCSqlGenStrategy extends SqlGenStrategy {
private static final Logger keyPipelineLog = LoggerFactory.getLogger("keyPipeline");
public static final String APP_KEY = "S2SQL_PARSER";
public static final String INSTRUCTION = ""
+ "\n#Role: You are a data analyst experienced in SQL languages."
+ "#Role: You are a data analyst experienced in SQL languages."
+ "\n#Task: You will be provided with a natural language question asked by users,"
+ "please convert it to a SQL query so that relevant data could be returned "
+ "by executing the SQL query against underlying database." + "\n#Rules:"
@@ -66,7 +70,7 @@ public class OnePassSCSqlGenStrategy extends SqlGenStrategy {
LLMResp llmResp = new LLMResp();
llmResp.setQuery(llmReq.getQueryText());
// 1.recall exemplars
keyPipelineLog.info("OnePassSCSqlGenStrategy llmReq:\n{}", llmReq);
log.info("OnePassSCSqlGenStrategy llmReq:\n{}", llmReq);
List<List<Text2SQLExemplar>> exemplarsList = promptHelper.getFewShotExemplars(llmReq);
// 2.generate sql generation prompt for each self-consistency inference
@@ -85,10 +89,9 @@ public class OnePassSCSqlGenStrategy extends SqlGenStrategy {
// 3.perform multiple self-consistency inferences parallelly
Map<String, Prompt> output2Prompt = new ConcurrentHashMap<>();
prompt2Exemplar.keySet().parallelStream().forEach(prompt -> {
keyPipelineLog.info("OnePassSCSqlGenStrategy reqPrompt:\n{}", prompt.toUserMessage());
SemanticSql s2Sql = extractor.generateSemanticSql(prompt.toUserMessage().singleText());
output2Prompt.put(s2Sql.getSql(), prompt);
keyPipelineLog.info("OnePassSCSqlGenStrategy modelResp:\n{}", s2Sql.getSql());
keyPipelineLog.info("OnePassSCSqlGenStrategy modelReq:\n{} \nmodelResp:\n{}", prompt.text(), s2Sql);
});
// 4.format response.

View File

@@ -5,8 +5,6 @@ import com.tencent.supersonic.headless.chat.query.llm.s2sql.LLMReq;
import com.tencent.supersonic.headless.chat.query.llm.s2sql.LLMResp;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.provider.ModelProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -18,8 +16,6 @@ import org.springframework.stereotype.Service;
@Service
public abstract class SqlGenStrategy implements InitializingBean {
protected static final Logger keyPipelineLog = LoggerFactory.getLogger("keyPipeline");
@Autowired
protected PromptHelper promptHelper;