From 682d35b2b29005654e08cbb2d43761eb11f2022c Mon Sep 17 00:00:00 2001 From: lexluo09 <39718951+lexluo09@users.noreply.github.com> Date: Thu, 14 Sep 2023 22:59:11 +0800 Subject: [PATCH] (improvement)(chat) update llm url to llmParser in chat project (#92) --- assembly/bin/supersonic-daemon.sh | 3 +++ .../{LLMConfig.java => LLMParserConfig.java} | 4 ++-- .../chat/parser/llm/dsl/LLMDslParser.java | 14 +++++++------- .../chat/src/main/resources/application-local.yaml | 3 ++- .../src/main/resources/application-local.yaml | 4 +++- 5 files changed, 17 insertions(+), 11 deletions(-) rename chat/core/src/main/java/com/tencent/supersonic/chat/config/{LLMConfig.java => LLMParserConfig.java} (83%) diff --git a/assembly/bin/supersonic-daemon.sh b/assembly/bin/supersonic-daemon.sh index 42a4a7e9b..1e5333b9a 100644 --- a/assembly/bin/supersonic-daemon.sh +++ b/assembly/bin/supersonic-daemon.sh @@ -58,6 +58,9 @@ function setEnvToWeb { } function resetEnvironment { + if [[ ${app_name} == $LLMPARSER_APP_NAME ]]; then + return + fi if [[ "$command" == "start" || "$command" == "restart" ]]; then #1. clear file mkdir -p ${runtimeDir} diff --git a/chat/core/src/main/java/com/tencent/supersonic/chat/config/LLMConfig.java b/chat/core/src/main/java/com/tencent/supersonic/chat/config/LLMParserConfig.java similarity index 83% rename from chat/core/src/main/java/com/tencent/supersonic/chat/config/LLMConfig.java rename to chat/core/src/main/java/com/tencent/supersonic/chat/config/LLMParserConfig.java index 844291bac..e44029538 100644 --- a/chat/core/src/main/java/com/tencent/supersonic/chat/config/LLMConfig.java +++ b/chat/core/src/main/java/com/tencent/supersonic/chat/config/LLMParserConfig.java @@ -7,10 +7,10 @@ import org.springframework.context.annotation.Configuration; @Configuration @Data -public class LLMConfig { +public class LLMParserConfig { - @Value("${llm.url:}") + @Value("${llm.parser.url:}") private String url; @Value("${query2sql.path:/query2sql}") diff --git a/chat/core/src/main/java/com/tencent/supersonic/chat/parser/llm/dsl/LLMDslParser.java b/chat/core/src/main/java/com/tencent/supersonic/chat/parser/llm/dsl/LLMDslParser.java index e9984407c..9d486d6e9 100644 --- a/chat/core/src/main/java/com/tencent/supersonic/chat/parser/llm/dsl/LLMDslParser.java +++ b/chat/core/src/main/java/com/tencent/supersonic/chat/parser/llm/dsl/LLMDslParser.java @@ -15,7 +15,7 @@ import com.tencent.supersonic.chat.api.pojo.SemanticParseInfo; import com.tencent.supersonic.chat.api.pojo.SemanticSchema; import com.tencent.supersonic.chat.api.pojo.request.QueryFilter; import com.tencent.supersonic.chat.api.pojo.request.QueryReq; -import com.tencent.supersonic.chat.config.LLMConfig; +import com.tencent.supersonic.chat.config.LLMParserConfig; import com.tencent.supersonic.chat.corrector.BaseSemanticCorrector; import com.tencent.supersonic.chat.parser.SatisfactionChecker; import com.tencent.supersonic.chat.parser.plugin.function.ModelResolver; @@ -66,9 +66,9 @@ public class LLMDslParser implements SemanticParser { @Override public void parse(QueryContext queryCtx, ChatContext chatCtx) { QueryReq request = queryCtx.getRequest(); - LLMConfig llmConfig = ContextUtils.getBean(LLMConfig.class); - if (StringUtils.isEmpty(llmConfig.getUrl())) { - log.info("llm url is empty, skip dsl parser, llmConfig:{}", llmConfig); + LLMParserConfig llmParserConfig = ContextUtils.getBean(LLMParserConfig.class); + if (StringUtils.isEmpty(llmParserConfig.getUrl())) { + log.info("llm parser url is empty, skip dsl parser, llmParserConfig:{}", llmParserConfig); return; } if (SatisfactionChecker.check(queryCtx)) { @@ -88,7 +88,7 @@ public class LLMDslParser implements SemanticParser { } LLMReq llmReq = getLlmReq(queryCtx, modelId); - LLMResp llmResp = requestLLM(llmReq, modelId, llmConfig); + LLMResp llmResp = requestLLM(llmReq, modelId, llmParserConfig); if (Objects.isNull(llmResp)) { return; @@ -319,8 +319,8 @@ public class LLMDslParser implements SemanticParser { return modelId; } - private LLMResp requestLLM(LLMReq llmReq, Long modelId, LLMConfig llmConfig) { - String questUrl = llmConfig.getUrl() + llmConfig.getQueryToSqlPath(); + private LLMResp requestLLM(LLMReq llmReq, Long modelId, LLMParserConfig llmParserConfig) { + String questUrl = llmParserConfig.getUrl() + llmParserConfig.getQueryToSqlPath(); long startTime = System.currentTimeMillis(); log.info("requestLLM request, modelId:{},llmReq:{}", modelId, llmReq); RestTemplate restTemplate = ContextUtils.getBean(RestTemplate.class); diff --git a/launchers/chat/src/main/resources/application-local.yaml b/launchers/chat/src/main/resources/application-local.yaml index 56919ce15..e3a79dca4 100644 --- a/launchers/chat/src/main/resources/application-local.yaml +++ b/launchers/chat/src/main/resources/application-local.yaml @@ -29,4 +29,5 @@ semantic: prefix: http://127.0.0.1:9081 llm: - url: http://127.0.0.1:9092/ + parser: + url: http://127.0.0.1:9092 diff --git a/launchers/standalone/src/main/resources/application-local.yaml b/launchers/standalone/src/main/resources/application-local.yaml index bd552365d..4ef787b5c 100644 --- a/launchers/standalone/src/main/resources/application-local.yaml +++ b/launchers/standalone/src/main/resources/application-local.yaml @@ -36,8 +36,10 @@ time: mybatis: mapper-locations=classpath:mappers/custom/*.xml,classpath*:/mappers/*.xml + llm: - url: http://127.0.0.1:9092 + parser: + url: http://127.0.0.1:9092 embedding: url: http://127.0.0.1:9092 functionCall: