mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 11:07:06 +00:00
[improvement](chat) Adjust related packages, add other SqlGeneration implementations, and rename EmbedLLMProxy to JavaLLMProxy. (#489)
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
package com.tencent.supersonic.chat.parser;
|
package com.tencent.supersonic.chat.parser;
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
import com.tencent.supersonic.chat.api.pojo.QueryContext;
|
||||||
import com.tencent.supersonic.chat.parser.plugin.function.FunctionCallPromptGenerator;
|
import com.tencent.supersonic.chat.parser.plugin.function.FunctionPromptGenerator;
|
||||||
import com.tencent.supersonic.chat.parser.plugin.function.FunctionReq;
|
import com.tencent.supersonic.chat.parser.plugin.function.FunctionReq;
|
||||||
import com.tencent.supersonic.chat.parser.plugin.function.FunctionResp;
|
import com.tencent.supersonic.chat.parser.plugin.function.FunctionResp;
|
||||||
import com.tencent.supersonic.chat.parser.sql.llm.SqlGeneration;
|
import com.tencent.supersonic.chat.parser.sql.llm.SqlGeneration;
|
||||||
import com.tencent.supersonic.chat.parser.sql.llm.SqlGenerationFactory;
|
import com.tencent.supersonic.chat.parser.sql.llm.SqlGenerationFactory;
|
||||||
import com.tencent.supersonic.chat.parser.sql.llm.prompt.OutputFormat;
|
import com.tencent.supersonic.chat.parser.sql.llm.OutputFormat;
|
||||||
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq;
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq;
|
||||||
import com.tencent.supersonic.chat.query.llm.s2sql.LLMResp;
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMResp;
|
||||||
import com.tencent.supersonic.common.util.ContextUtils;
|
import com.tencent.supersonic.common.util.ContextUtils;
|
||||||
@@ -14,14 +14,17 @@ import dev.langchain4j.model.chat.ChatLanguageModel;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LLMProxy based on langchain4j Java version.
|
||||||
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class EmbedLLMProxy implements LLMProxy {
|
public class JavaLLMProxy implements LLMProxy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSkip(QueryContext queryContext) {
|
public boolean isSkip(QueryContext queryContext) {
|
||||||
ChatLanguageModel chatLanguageModel = ContextUtils.getBean(ChatLanguageModel.class);
|
ChatLanguageModel chatLanguageModel = ContextUtils.getBean(ChatLanguageModel.class);
|
||||||
if (Objects.isNull(chatLanguageModel)) {
|
if (Objects.isNull(chatLanguageModel)) {
|
||||||
log.warn("chatLanguageModel is null, skip EmbedLLMProxy");
|
log.warn("chatLanguageModel is null, skip :{}", JavaLLMProxy.class.getName());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -43,7 +46,7 @@ public class EmbedLLMProxy implements LLMProxy {
|
|||||||
@Override
|
@Override
|
||||||
public FunctionResp requestFunction(FunctionReq functionReq) {
|
public FunctionResp requestFunction(FunctionReq functionReq) {
|
||||||
|
|
||||||
FunctionCallPromptGenerator promptGenerator = ContextUtils.getBean(FunctionCallPromptGenerator.class);
|
FunctionPromptGenerator promptGenerator = ContextUtils.getBean(FunctionPromptGenerator.class);
|
||||||
|
|
||||||
String functionCallPrompt = promptGenerator.generateFunctionCallPrompt(functionReq.getQueryText(),
|
String functionCallPrompt = promptGenerator.generateFunctionCallPrompt(functionReq.getQueryText(),
|
||||||
functionReq.getPluginConfigs());
|
functionReq.getPluginConfigs());
|
||||||
@@ -32,7 +32,7 @@ public class PythonLLMProxy implements LLMProxy {
|
|||||||
public boolean isSkip(QueryContext queryContext) {
|
public boolean isSkip(QueryContext queryContext) {
|
||||||
LLMParserConfig llmParserConfig = ContextUtils.getBean(LLMParserConfig.class);
|
LLMParserConfig llmParserConfig = ContextUtils.getBean(LLMParserConfig.class);
|
||||||
if (StringUtils.isEmpty(llmParserConfig.getUrl())) {
|
if (StringUtils.isEmpty(llmParserConfig.getUrl())) {
|
||||||
log.warn("llmParserUrl is empty, skip PythonLLMProxy, config:{}", llmParserConfig);
|
log.warn("llmParserUrl is empty, skip :{}", PythonLLMProxy.class.getName());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.tencent.supersonic.chat.parser.plugin.function;
|
package com.tencent.supersonic.chat.parser.plugin.function;
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.parser.sql.llm.prompt.InputFormat;
|
import com.tencent.supersonic.chat.parser.sql.llm.InputFormat;
|
||||||
import com.tencent.supersonic.chat.plugin.PluginParseConfig;
|
import com.tencent.supersonic.chat.plugin.PluginParseConfig;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -9,7 +9,7 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class FunctionCallPromptGenerator {
|
public class FunctionPromptGenerator {
|
||||||
|
|
||||||
public String generateFunctionCallPrompt(String queryText, List<PluginParseConfig> toolConfigList) {
|
public String generateFunctionCallPrompt(String queryText, List<PluginParseConfig> toolConfigList) {
|
||||||
List<String> toolExplainList = toolConfigList.stream()
|
List<String> toolExplainList = toolConfigList.stream()
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.tencent.supersonic.chat.parser.sql.llm.prompt;
|
package com.tencent.supersonic.chat.parser.sql.llm;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.tencent.supersonic.chat.parser.sql.llm;
|
||||||
|
|
||||||
|
|
||||||
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq;
|
||||||
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq.SqlGenerationMode;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class OneStepsSqlGeneration implements SqlGeneration, InitializingBean {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generation(LLMReq llmReq, String modelClusterKey) {
|
||||||
|
//TODO
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet() {
|
||||||
|
SqlGenerationFactory.addSqlGenerationForFactory(SqlGenerationMode.ONE_STEP, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.tencent.supersonic.chat.parser.sql.llm.prompt;
|
package com.tencent.supersonic.chat.parser.sql.llm;
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.parser.plugin.function.FunctionResp;
|
import com.tencent.supersonic.chat.parser.plugin.function.FunctionResp;
|
||||||
import com.tencent.supersonic.common.util.JsonUtil;
|
import com.tencent.supersonic.common.util.JsonUtil;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.tencent.supersonic.chat.parser.sql.llm.prompt;
|
package com.tencent.supersonic.chat.parser.sql.llm;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.tencent.supersonic.chat.parser.sql.llm.prompt;
|
package com.tencent.supersonic.chat.parser.sql.llm;
|
||||||
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
@@ -3,6 +3,9 @@ package com.tencent.supersonic.chat.parser.sql.llm;
|
|||||||
|
|
||||||
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq;
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sql Generation
|
||||||
|
*/
|
||||||
public interface SqlGeneration {
|
public interface SqlGeneration {
|
||||||
|
|
||||||
String generation(LLMReq llmReq, String modelClusterKey);
|
String generation(LLMReq llmReq, String modelClusterKey);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.tencent.supersonic.chat.parser.sql.llm.prompt;
|
package com.tencent.supersonic.chat.parser.sql.llm;
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq.ElementValue;
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq.ElementValue;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.tencent.supersonic.chat.parser.sql.llm;
|
||||||
|
|
||||||
|
|
||||||
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq;
|
||||||
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq.SqlGenerationMode;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class TwoStepCSSqlGeneration implements SqlGeneration, InitializingBean {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generation(LLMReq llmReq, String modelClusterKey) {
|
||||||
|
//TODO
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet() {
|
||||||
|
SqlGenerationFactory.addSqlGenerationForFactory(SqlGenerationMode.TWO_STEP_CS, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,9 +2,6 @@ package com.tencent.supersonic.chat.parser.sql.llm;
|
|||||||
|
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.config.OptimizationConfig;
|
import com.tencent.supersonic.chat.config.OptimizationConfig;
|
||||||
import com.tencent.supersonic.chat.parser.sql.llm.prompt.OutputFormat;
|
|
||||||
import com.tencent.supersonic.chat.parser.sql.llm.prompt.SqlExampleLoader;
|
|
||||||
import com.tencent.supersonic.chat.parser.sql.llm.prompt.SqlPromptGenerator;
|
|
||||||
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq;
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq;
|
||||||
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq.ElementValue;
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq.ElementValue;
|
||||||
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq.SqlGenerationMode;
|
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq.SqlGenerationMode;
|
||||||
@@ -25,7 +22,7 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class TwoStepsSqlGeneration implements SqlGeneration, InitializingBean {
|
public class TwoStepSqlGeneration implements SqlGeneration, InitializingBean {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ChatLanguageModel chatLanguageModel;
|
private ChatLanguageModel chatLanguageModel;
|
||||||
@@ -68,6 +65,6 @@ public class TwoStepsSqlGeneration implements SqlGeneration, InitializingBean {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
SqlGenerationFactory.addSqlGenerationForFactory(SqlGenerationMode.TWO_STEPS, this);
|
SqlGenerationFactory.addSqlGenerationForFactory(SqlGenerationMode.TWO_STEP, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ public class LLMReq {
|
|||||||
|
|
||||||
private String priorExts;
|
private String priorExts;
|
||||||
|
|
||||||
private SqlGenerationMode sqlGenerationMode = SqlGenerationMode.TWO_STEPS;
|
private SqlGenerationMode sqlGenerationMode = SqlGenerationMode.TWO_STEP;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class ElementValue {
|
public static class ElementValue {
|
||||||
@@ -50,9 +50,9 @@ public class LLMReq {
|
|||||||
|
|
||||||
ONE_STEP("ONE_STEP"),
|
ONE_STEP("ONE_STEP"),
|
||||||
|
|
||||||
TWO_STEPS("TWO_STEPS"),
|
TWO_STEP("TWO_STEP"),
|
||||||
|
|
||||||
TWO_STEPS_WITH_CS("TWO_STEPS_WITH_CS");
|
TWO_STEP_CS("TWO_STEP_CS");
|
||||||
|
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.tencent.supersonic;
|
package com.tencent.supersonic;
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.config.OptimizationConfig;
|
import com.tencent.supersonic.chat.config.OptimizationConfig;
|
||||||
import com.tencent.supersonic.chat.parser.sql.llm.prompt.SqlExample;
|
import com.tencent.supersonic.chat.parser.sql.llm.SqlExample;
|
||||||
import com.tencent.supersonic.chat.parser.sql.llm.prompt.SqlExampleLoader;
|
import com.tencent.supersonic.chat.parser.sql.llm.SqlExampleLoader;
|
||||||
import com.tencent.supersonic.chat.parser.EmbedLLMProxy;
|
import com.tencent.supersonic.chat.parser.JavaLLMProxy;
|
||||||
import com.tencent.supersonic.chat.parser.LLMProxy;
|
import com.tencent.supersonic.chat.parser.LLMProxy;
|
||||||
import com.tencent.supersonic.chat.utils.ComponentFactory;
|
import com.tencent.supersonic.chat.utils.ComponentFactory;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -31,7 +31,7 @@ public class EmbeddingInitListener implements CommandLineRunner {
|
|||||||
|
|
||||||
public void initSqlExamples() {
|
public void initSqlExamples() {
|
||||||
try {
|
try {
|
||||||
if (llmProxy instanceof EmbedLLMProxy) {
|
if (llmProxy instanceof JavaLLMProxy) {
|
||||||
List<SqlExample> sqlExamples = sqlExampleLoader.getSqlExamples();
|
List<SqlExample> sqlExamples = sqlExampleLoader.getSqlExamples();
|
||||||
String collectionName = optimizationConfig.getText2sqlCollectionName();
|
String collectionName = optimizationConfig.getText2sqlCollectionName();
|
||||||
sqlExampleLoader.addEmbeddingStore(sqlExamples, collectionName);
|
sqlExampleLoader.addEmbeddingStore(sqlExamples, collectionName);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ com.tencent.supersonic.chat.processor.ParseResultProcessor=\
|
|||||||
com.tencent.supersonic.chat.processor.RespBuildProcessor
|
com.tencent.supersonic.chat.processor.RespBuildProcessor
|
||||||
|
|
||||||
com.tencent.supersonic.chat.parser.LLMProxy=\
|
com.tencent.supersonic.chat.parser.LLMProxy=\
|
||||||
com.tencent.supersonic.chat.parser.EmbedLLMProxy
|
com.tencent.supersonic.chat.parser.JavaLLMProxy
|
||||||
|
|
||||||
com.tencent.supersonic.chat.api.component.SemanticInterpreter=\
|
com.tencent.supersonic.chat.api.component.SemanticInterpreter=\
|
||||||
com.tencent.supersonic.knowledge.semantic.LocalSemanticInterpreter
|
com.tencent.supersonic.knowledge.semantic.LocalSemanticInterpreter
|
||||||
|
|||||||
Reference in New Issue
Block a user