mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 04:27:39 +00:00
(improvement)(chat)Add endpoint service to test LLM connection. #1135
This commit is contained in:
@@ -79,4 +79,4 @@ Please follow SuperSonic wechat official account:
|
|||||||
|
|
||||||
Welcome to join the WeChat community:
|
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"/>
|
||||||
@@ -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"/>
|
||||||
@@ -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.Agent;
|
||||||
import com.tencent.supersonic.chat.server.agent.AgentToolType;
|
import com.tencent.supersonic.chat.server.agent.AgentToolType;
|
||||||
import com.tencent.supersonic.chat.server.service.AgentService;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
@@ -49,6 +51,11 @@ public class AgentController {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/testLLMConn")
|
||||||
|
public boolean testLLMConn(@RequestBody LLMConfig llmConfig) {
|
||||||
|
return LLMConnHelper.testConnection(llmConfig);
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping("/getAgentList")
|
@RequestMapping("/getAgentList")
|
||||||
public List<Agent> getAgentList() {
|
public List<Agent> getAgentList() {
|
||||||
return agentService.getAgents();
|
return agentService.getAgents();
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import com.tencent.supersonic.chat.api.pojo.response.ChatConfigRichResp;
|
|||||||
import com.tencent.supersonic.chat.server.config.ChatConfig;
|
import com.tencent.supersonic.chat.server.config.ChatConfig;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public interface ConfigService {
|
public interface ConfigService {
|
||||||
|
|
||||||
@@ -21,8 +20,6 @@ public interface ConfigService {
|
|||||||
|
|
||||||
ItemNameVisibilityInfo getItemNameVisibility(ChatConfig chatConfig);
|
ItemNameVisibilityInfo getItemNameVisibility(ChatConfig chatConfig);
|
||||||
|
|
||||||
ItemNameVisibilityInfo getVisibilityByModelId(Long modelId);
|
|
||||||
|
|
||||||
List<ChatConfigResp> search(ChatConfigFilter filter, User user);
|
List<ChatConfigResp> search(ChatConfigFilter filter, User user);
|
||||||
|
|
||||||
ChatConfigRichResp getConfigRichInfo(Long modelId);
|
ChatConfigRichResp getConfigRichInfo(Long modelId);
|
||||||
@@ -31,5 +28,4 @@ public interface ConfigService {
|
|||||||
|
|
||||||
List<ChatConfigRichResp> getAllChatRichConfig();
|
List<ChatConfigRichResp> getAllChatRichConfig();
|
||||||
|
|
||||||
Map<Long, ChatConfigRichResp> getModelIdToChatRichConfig();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -342,11 +342,4 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
return new ArrayList<>();
|
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 |
Reference in New Issue
Block a user