(fix)(chat&headless)Agent references ChatModelConfig instead of ModelConfig.

This commit is contained in:
jerryjzhang
2024-07-12 11:58:38 +08:00
parent 37da1ac2ae
commit 5bf4a4160d
12 changed files with 37 additions and 36 deletions

View File

@@ -4,7 +4,7 @@ package com.tencent.supersonic.chat.server.agent;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.tencent.supersonic.common.config.ModelConfig;
import com.tencent.supersonic.common.config.ChatModelConfig;
import com.tencent.supersonic.common.config.PromptConfig;
import com.tencent.supersonic.common.config.VisualConfig;
import com.tencent.supersonic.common.pojo.RecordInfo;
@@ -34,7 +34,7 @@ public class Agent extends RecordInfo {
private Integer status;
private List<String> examples;
private String agentConfig;
private ModelConfig modelConfig;
private ChatModelConfig modelConfig;
private PromptConfig promptConfig;
private MultiTurnConfig multiTurnConfig;
private VisualConfig visualConfig;

View File

@@ -6,7 +6,7 @@ import com.tencent.supersonic.chat.server.agent.Agent;
import com.tencent.supersonic.chat.server.agent.AgentToolType;
import com.tencent.supersonic.chat.server.service.AgentService;
import com.tencent.supersonic.chat.server.util.LLMConnHelper;
import com.tencent.supersonic.common.config.ModelConfig;
import com.tencent.supersonic.common.config.ChatModelConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
@@ -51,7 +51,7 @@ public class AgentController {
}
@PostMapping("/testLLMConn")
public boolean testLLMConn(@RequestBody ModelConfig modelConfig) {
public boolean testLLMConn(@RequestBody ChatModelConfig modelConfig) {
return LLMConnHelper.testConnection(modelConfig);
}

View File

@@ -12,7 +12,7 @@ import com.tencent.supersonic.chat.server.service.AgentService;
import com.tencent.supersonic.chat.server.service.ChatService;
import com.tencent.supersonic.chat.server.service.MemoryService;
import com.tencent.supersonic.chat.server.util.LLMConnHelper;
import com.tencent.supersonic.common.config.ModelConfig;
import com.tencent.supersonic.common.config.ChatModelConfig;
import com.tencent.supersonic.common.config.PromptConfig;
import com.tencent.supersonic.common.config.VisualConfig;
import com.tencent.supersonic.common.util.JsonUtil;
@@ -122,7 +122,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentDOMapper, AgentDO>
BeanUtils.copyProperties(agentDO, agent);
agent.setAgentConfig(agentDO.getConfig());
agent.setExamples(JsonUtil.toList(agentDO.getExamples(), String.class));
agent.setModelConfig(JsonUtil.toObject(agentDO.getModelConfig(), ModelConfig.class));
agent.setModelConfig(JsonUtil.toObject(agentDO.getModelConfig(), ChatModelConfig.class));
agent.setPromptConfig(JsonUtil.toObject(agentDO.getPromptConfig(), PromptConfig.class));
agent.setMultiTurnConfig(JsonUtil.toObject(agentDO.getMultiTurnConfig(), MultiTurnConfig.class));
agent.setVisualConfig(JsonUtil.toObject(agentDO.getVisualConfig(), VisualConfig.class));

View File

@@ -1,6 +1,6 @@
package com.tencent.supersonic.chat.server.util;
import com.tencent.supersonic.common.config.ModelConfig;
import com.tencent.supersonic.common.config.ChatModelConfig;
import com.tencent.supersonic.common.pojo.exception.InvalidArgumentException;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.provider.ModelProvider;
@@ -9,10 +9,9 @@ import org.apache.commons.lang3.StringUtils;
@Slf4j
public class LLMConnHelper {
public static boolean testConnection(ModelConfig modelConfig) {
public static boolean testConnection(ChatModelConfig modelConfig) {
try {
if (modelConfig == null || modelConfig.getChatModel() == null
|| StringUtils.isBlank(modelConfig.getChatModel().getBaseUrl())) {
if (modelConfig == null || StringUtils.isBlank(modelConfig.getBaseUrl())) {
return false;
}
ChatLanguageModel chatLanguageModel = ModelProvider.getChatModel(modelConfig);

View File

@@ -18,11 +18,18 @@ public class QueryReqConverter {
if (agent == null) {
return queryNLReq;
}
if (agent.containsLLMParserTool() && agent.containsRuleTool()) {
queryNLReq.setText2SQLType(Text2SQLType.RULE_AND_LLM);
} else if (agent.containsLLMParserTool()) {
boolean hasLLMTool = agent.containsLLMParserTool();
boolean hasRuleTool = agent.containsRuleTool();
boolean hasLLMConfig = Objects.nonNull(agent.getModelConfig());
if (hasLLMTool && hasLLMConfig) {
queryNLReq.setText2SQLType(Text2SQLType.ONLY_LLM);
} else if (agent.containsRuleTool()) {
} else if (hasLLMTool && hasRuleTool) {
queryNLReq.setText2SQLType(Text2SQLType.RULE_AND_LLM);
} else if (hasLLMTool) {
queryNLReq.setText2SQLType(Text2SQLType.ONLY_LLM);
} else if (hasRuleTool) {
queryNLReq.setText2SQLType(Text2SQLType.ONLY_RULE);
}
queryNLReq.setDataSetIds(agent.getDataSetIds());