mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-19 00:37:08 +00:00
(improvement)(headless) Add support for the Ollama provider in the frontend and optimize the code (#1270)
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
package com.tencent.supersonic.common.pojo.enums;
|
||||
|
||||
public enum S2ModelProvider {
|
||||
|
||||
OPEN_AI,
|
||||
HUGGING_FACE,
|
||||
LOCAL_AI,
|
||||
IN_PROCESS
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.tencent.supersonic.common.util;
|
||||
|
||||
import com.tencent.supersonic.common.config.LLMConfig;
|
||||
import com.tencent.supersonic.common.pojo.enums.S2ModelProvider;
|
||||
import dev.langchain4j.model.chat.ChatLanguageModel;
|
||||
import dev.langchain4j.model.localai.LocalAiChatModel;
|
||||
import dev.langchain4j.model.openai.OpenAiChatModel;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
public class S2ChatModelProvider {
|
||||
|
||||
public static ChatLanguageModel provide(LLMConfig llmConfig) {
|
||||
ChatLanguageModel chatLanguageModel = ContextUtils.getBean(ChatLanguageModel.class);
|
||||
if (llmConfig == null || StringUtils.isBlank(llmConfig.getProvider())
|
||||
|| StringUtils.isBlank(llmConfig.getBaseUrl())) {
|
||||
return chatLanguageModel;
|
||||
}
|
||||
if (S2ModelProvider.OPEN_AI.name().equalsIgnoreCase(llmConfig.getProvider())) {
|
||||
return OpenAiChatModel
|
||||
.builder()
|
||||
.baseUrl(llmConfig.getBaseUrl())
|
||||
.modelName(llmConfig.getModelName())
|
||||
.apiKey(llmConfig.keyDecrypt())
|
||||
.temperature(llmConfig.getTemperature())
|
||||
.timeout(Duration.ofSeconds(llmConfig.getTimeOut()))
|
||||
.build();
|
||||
} else if (S2ModelProvider.LOCAL_AI.name().equalsIgnoreCase(llmConfig.getProvider())) {
|
||||
return LocalAiChatModel
|
||||
.builder()
|
||||
.baseUrl(llmConfig.getBaseUrl())
|
||||
.modelName(llmConfig.getModelName())
|
||||
.temperature(llmConfig.getTemperature())
|
||||
.timeout(Duration.ofSeconds(llmConfig.getTimeOut()))
|
||||
.build();
|
||||
}
|
||||
throw new RuntimeException("unsupported provider: " + llmConfig.getProvider());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user