(improvement)(chat) Support embedding store configuration. (#1363)

This commit is contained in:
lexluo09
2024-07-07 00:30:19 +08:00
committed by GitHub
parent 3f460429e6
commit 4d7bfe07aa
37 changed files with 185 additions and 119 deletions

View File

@@ -15,24 +15,11 @@ import java.util.Objects;
public class ModelProvider {
private static final Map<String, ModelFactory> factories = new HashMap<>();
public static void add(Provider provider, ModelFactory modelFactory) {
factories.put(provider.name(), modelFactory);
public static void add(String provider, ModelFactory modelFactory) {
factories.put(provider, modelFactory);
}
public static ChatLanguageModel provideChatModel(ChatModelConfig llmConfig) {
if (llmConfig == null || StringUtils.isBlank(llmConfig.getProvider())
|| StringUtils.isBlank(llmConfig.getBaseUrl())) {
return ContextUtils.getBean(ChatLanguageModel.class);
}
ModelFactory modelFactory = factories.get(llmConfig.getProvider().toUpperCase());
if (modelFactory != null) {
return modelFactory.createChatModel(llmConfig);
}
throw new RuntimeException("Unsupported ChatLanguageModel provider: " + llmConfig.getProvider());
}
public static ChatLanguageModel provideChatModelNew(ModelConfig modelConfig) {
public static ChatLanguageModel getChatModel(ModelConfig modelConfig) {
if (modelConfig == null || modelConfig.getChatModel() == null
|| StringUtils.isBlank(modelConfig.getChatModel().getProvider())
|| StringUtils.isBlank(modelConfig.getChatModel().getBaseUrl())) {
@@ -47,7 +34,7 @@ public class ModelProvider {
throw new RuntimeException("Unsupported ChatLanguageModel provider: " + chatModel.getProvider());
}
public static EmbeddingModel provideEmbeddingModel(ModelConfig modelConfig) {
public static EmbeddingModel getEmbeddingModel(ModelConfig modelConfig) {
if (modelConfig == null || Objects.isNull(modelConfig.getEmbeddingModel())
|| StringUtils.isBlank(modelConfig.getEmbeddingModel().getBaseUrl())
|| StringUtils.isBlank(modelConfig.getEmbeddingModel().getProvider())) {