(improvement)(chat)Add endpoint service to test LLM connection. #1135

This commit is contained in:
jerryjzhang
2024-06-15 09:40:32 +08:00
parent eb18857a9b
commit 67cbc43956
8 changed files with 27 additions and 13 deletions

View File

@@ -79,4 +79,4 @@ Please follow SuperSonic wechat official account:
Welcome to join the WeChat community:
<img src="./docs/images/supersonic_wechat.jpg" height="50%" width="50%" align="center"/>
<img src="./docs/images/supersonic_wechat.png" height="50%" width="50%" align="center"/>

View File

@@ -77,4 +77,4 @@ SuperSonic自带样例的语义模型和问答对话只需以下三步即可
欢迎加入微信社群:
<img src="./docs/images/supersonic_wechat.jpg" height="50%" width="50%" align="center"/>
<img src="./docs/images/supersonic_wechat.png" height="50%" width="50%" align="center"/>

View File

@@ -5,6 +5,8 @@ import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
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.LLMConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
@@ -49,6 +51,11 @@ public class AgentController {
return true;
}
@PostMapping("/testLLMConn")
public boolean testLLMConn(@RequestBody LLMConfig llmConfig) {
return LLMConnHelper.testConnection(llmConfig);
}
@RequestMapping("/getAgentList")
public List<Agent> getAgentList() {
return agentService.getAgents();

View File

@@ -11,7 +11,6 @@ import com.tencent.supersonic.chat.api.pojo.response.ChatConfigRichResp;
import com.tencent.supersonic.chat.server.config.ChatConfig;
import java.util.List;
import java.util.Map;
public interface ConfigService {
@@ -21,8 +20,6 @@ public interface ConfigService {
ItemNameVisibilityInfo getItemNameVisibility(ChatConfig chatConfig);
ItemNameVisibilityInfo getVisibilityByModelId(Long modelId);
List<ChatConfigResp> search(ChatConfigFilter filter, User user);
ChatConfigRichResp getConfigRichInfo(Long modelId);
@@ -31,5 +28,4 @@ public interface ConfigService {
List<ChatConfigRichResp> getAllChatRichConfig();
Map<Long, ChatConfigRichResp> getModelIdToChatRichConfig();
}

View File

@@ -342,11 +342,4 @@ public class ConfigServiceImpl implements ConfigService {
return new ArrayList<>();
}
@Override
public Map<Long, ChatConfigRichResp> getModelIdToChatRichConfig() {
List<ChatConfigRichResp> allChatRichConfig = getAllChatRichConfig();
return allChatRichConfig.stream()
.collect(Collectors.toMap(ChatConfigRichResp::getModelId, value -> value, (k1, k2) -> k1));
}
}

View File

@@ -0,0 +1,18 @@
package com.tencent.supersonic.chat.server.util;
import com.tencent.supersonic.common.config.LLMConfig;
import com.tencent.supersonic.common.util.S2ChatModelProvider;
import dev.langchain4j.model.chat.ChatLanguageModel;
import org.apache.commons.lang3.StringUtils;
public class LLMConnHelper {
public static boolean testConnection(LLMConfig llmConfig) {
try {
ChatLanguageModel chatLanguageModel = S2ChatModelProvider.provide(llmConfig);
String response = chatLanguageModel.generate("Hi there");
return StringUtils.isNotEmpty(response) ? true : false;
} catch (Exception e) {
return false;
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 178 KiB