[improvement][chat]Rename LLMInterpreter as LLMProxy

This commit is contained in:
jerryjzhang
2023-11-29 16:57:48 +08:00
parent 57f7d0c67d
commit 82cfb3050d
12 changed files with 35 additions and 31 deletions

View File

@@ -1,6 +1,6 @@
package com.tencent.supersonic.chat.agent;
import com.tencent.supersonic.chat.parser.llm.interpret.MetricOption;
import com.tencent.supersonic.chat.parser.llm.analytics.MetricOption;
import lombok.Data;
import java.util.List;

View File

@@ -6,10 +6,11 @@ import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq;
import com.tencent.supersonic.chat.query.llm.s2sql.LLMResp;
/**
* Unified interpreter for invoking the llm layer.
* LLMProxy encapsulates functions performed by LLMs so that multiple
* orchestration frameworks (e.g. LangChain in python, LangChain4j in java)
* could be used.
*/
public interface LLMInterpreter {
public interface LLMProxy {
LLMResp query2sql(LLMReq llmReq, String modelClusterKey);

View File

@@ -20,8 +20,11 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
/**
* PythonLLMProxy sends requests to LangChain-based python service.
*/
@Slf4j
public class HttpLLMInterpreter implements LLMInterpreter {
public class PythonLLMProxy implements LLMProxy {
public LLMResp query2sql(LLMReq llmReq, String modelClusterKey) {

View File

@@ -1,4 +1,4 @@
package com.tencent.supersonic.chat.parser.llm.interpret;
package com.tencent.supersonic.chat.parser.llm.analytics;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Sets;
@@ -34,12 +34,12 @@ import java.util.Set;
import java.util.stream.Collectors;
@Slf4j
public class MetricInterpretParser implements SemanticParser {
public class MetricAnalyzeParser implements SemanticParser {
@Override
public void parse(QueryContext queryContext, ChatContext chatContext) {
if (SatisfactionChecker.check(queryContext)) {
log.info("skip MetricInterpretParser");
log.info("skip MetricAnalyzeParser");
return;
}
Map<Long, DataAnalyticsTool> metricInterpretToolMap =

View File

@@ -1,4 +1,4 @@
package com.tencent.supersonic.chat.parser.llm.interpret;
package com.tencent.supersonic.chat.parser.llm.analytics;
import lombok.AllArgsConstructor;

View File

@@ -12,7 +12,7 @@ import com.tencent.supersonic.chat.api.pojo.SemanticSchema;
import com.tencent.supersonic.chat.api.pojo.request.QueryReq;
import com.tencent.supersonic.chat.config.LLMParserConfig;
import com.tencent.supersonic.chat.config.OptimizationConfig;
import com.tencent.supersonic.chat.parser.LLMInterpreter;
import com.tencent.supersonic.chat.parser.LLMProxy;
import com.tencent.supersonic.chat.parser.SatisfactionChecker;
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq;
import com.tencent.supersonic.chat.query.llm.s2sql.LLMReq.ElementValue;
@@ -47,7 +47,7 @@ import java.util.stream.Collectors;
@Service
public class LLMRequestService {
protected LLMInterpreter llmInterpreter = ComponentFactory.getLLMInterpreter();
protected LLMProxy llmProxy = ComponentFactory.getLLMProxy();
protected SemanticInterpreter semanticInterpreter = ComponentFactory.getSemanticLayer();
@Autowired
@@ -143,7 +143,7 @@ public class LLMRequestService {
}
public LLMResp requestLLM(LLMReq llmReq, String modelClusterKey) {
return llmInterpreter.query2sql(llmReq, modelClusterKey);
return llmProxy.query2sql(llmReq, modelClusterKey);
}
protected List<String> getFieldNameList(QueryContext queryCtx, ModelCluster modelCluster,

View File

@@ -2,8 +2,8 @@ package com.tencent.supersonic.chat.parser.plugin.embedding;
import com.google.common.collect.Lists;
import com.tencent.supersonic.chat.api.pojo.QueryContext;
import com.tencent.supersonic.chat.parser.HttpLLMInterpreter;
import com.tencent.supersonic.chat.parser.LLMInterpreter;
import com.tencent.supersonic.chat.parser.PythonLLMProxy;
import com.tencent.supersonic.chat.parser.LLMProxy;
import com.tencent.supersonic.chat.parser.ParseMode;
import com.tencent.supersonic.chat.parser.plugin.PluginParser;
import com.tencent.supersonic.chat.plugin.Plugin;
@@ -25,12 +25,12 @@ import org.springframework.util.CollectionUtils;
@Slf4j
public class EmbeddingBasedParser extends PluginParser {
protected LLMInterpreter llmInterpreter = ComponentFactory.getLLMInterpreter();
protected LLMProxy llmInterpreter = ComponentFactory.getLLMProxy();
@Override
public boolean checkPreCondition(QueryContext queryContext) {
EmbeddingConfig embeddingConfig = ContextUtils.getBean(EmbeddingConfig.class);
if (StringUtils.isBlank(embeddingConfig.getUrl()) && llmInterpreter instanceof HttpLLMInterpreter) {
if (StringUtils.isBlank(embeddingConfig.getUrl()) && llmInterpreter instanceof PythonLLMProxy) {
return false;
}
List<Plugin> plugins = getPluginList(queryContext);

View File

@@ -1,8 +1,8 @@
package com.tencent.supersonic.chat.parser.plugin.function;
import com.tencent.supersonic.chat.api.pojo.QueryContext;
import com.tencent.supersonic.chat.parser.HttpLLMInterpreter;
import com.tencent.supersonic.chat.parser.LLMInterpreter;
import com.tencent.supersonic.chat.parser.PythonLLMProxy;
import com.tencent.supersonic.chat.parser.LLMProxy;
import com.tencent.supersonic.chat.parser.ParseMode;
import com.tencent.supersonic.chat.parser.plugin.PluginParser;
import com.tencent.supersonic.chat.plugin.Plugin;
@@ -27,13 +27,13 @@ import org.springframework.util.CollectionUtils;
@Slf4j
public class FunctionBasedParser extends PluginParser {
protected LLMInterpreter llmInterpreter = ComponentFactory.getLLMInterpreter();
protected LLMProxy llmInterpreter = ComponentFactory.getLLMProxy();
@Override
public boolean checkPreCondition(QueryContext queryContext) {
FunctionCallConfig functionCallConfig = ContextUtils.getBean(FunctionCallConfig.class);
String functionUrl = functionCallConfig.getUrl();
if (StringUtils.isBlank(functionUrl) && llmInterpreter instanceof HttpLLMInterpreter) {
if (StringUtils.isBlank(functionUrl) && llmInterpreter instanceof PythonLLMProxy) {
log.info("functionUrl:{}, skip function parser, queryText:{}", functionUrl,
queryContext.getRequest().getQueryText());
return false;

View File

@@ -4,7 +4,7 @@ import com.tencent.supersonic.chat.api.component.SchemaMapper;
import com.tencent.supersonic.chat.api.component.SemanticCorrector;
import com.tencent.supersonic.chat.api.component.SemanticInterpreter;
import com.tencent.supersonic.chat.api.component.SemanticParser;
import com.tencent.supersonic.chat.parser.LLMInterpreter;
import com.tencent.supersonic.chat.parser.LLMProxy;
import com.tencent.supersonic.chat.parser.llm.s2sql.ModelResolver;
import com.tencent.supersonic.chat.processor.ResponseProcessor;
import com.tencent.supersonic.chat.responder.QueryResponder;
@@ -21,7 +21,7 @@ public class ComponentFactory {
private static List<SemanticCorrector> semanticCorrectors = new ArrayList<>();
private static SemanticInterpreter semanticInterpreter;
private static LLMInterpreter llmInterpreter;
private static LLMProxy llmProxy;
private static List<ResponseProcessor> responseProcessors = new ArrayList<>();
private static List<QueryResponder> executeResponders = new ArrayList<>();
private static ModelResolver modelResolver;
@@ -56,11 +56,11 @@ public class ComponentFactory {
return semanticInterpreter;
}
public static LLMInterpreter getLLMInterpreter() {
if (Objects.isNull(llmInterpreter)) {
llmInterpreter = init(LLMInterpreter.class);
public static LLMProxy getLLMProxy() {
if (Objects.isNull(llmProxy)) {
llmProxy = init(LLMProxy.class);
}
return llmInterpreter;
return llmProxy;
}
public static ModelResolver getModelResolver() {

View File

@@ -19,8 +19,8 @@ com.tencent.supersonic.chat.api.component.SemanticCorrector=\
com.tencent.supersonic.chat.corrector.GroupByCorrector, \
com.tencent.supersonic.chat.corrector.HavingCorrector
com.tencent.supersonic.chat.parser.LLMInterpreter=\
com.tencent.supersonic.chat.parser.HttpLLMInterpreter
com.tencent.supersonic.chat.parser.LLMProxy=\
com.tencent.supersonic.chat.parser.PythonLLMProxy
com.tencent.supersonic.chat.api.component.SemanticInterpreter=\
com.tencent.supersonic.knowledge.semantic.RemoteSemanticInterpreter

View File

@@ -30,8 +30,8 @@ com.tencent.supersonic.chat.processor.ResponseProcessor=\
com.tencent.supersonic.chat.processor.TimeCostProcessor, \
com.tencent.supersonic.chat.processor.RespBuildProcessor
com.tencent.supersonic.chat.parser.LLMInterpreter=\
com.tencent.supersonic.chat.parser.HttpLLMInterpreter
com.tencent.supersonic.chat.parser.LLMProxy=\
com.tencent.supersonic.chat.parser.PythonLLMProxy
com.tencent.supersonic.chat.api.component.SemanticInterpreter=\
com.tencent.supersonic.knowledge.semantic.LocalSemanticInterpreter

View File

@@ -13,7 +13,7 @@ import com.tencent.supersonic.chat.api.pojo.SchemaElement;
import com.tencent.supersonic.chat.api.pojo.SchemaElementType;
import com.tencent.supersonic.chat.api.pojo.request.QueryFilter;
import com.tencent.supersonic.chat.api.pojo.request.QueryReq;
import com.tencent.supersonic.chat.parser.llm.interpret.MetricOption;
import com.tencent.supersonic.chat.parser.llm.analytics.MetricOption;
import com.tencent.supersonic.common.pojo.DateConf;
import com.tencent.supersonic.common.pojo.enums.FilterOperatorEnum;