From 8f3e8e3bb7a7cab12b9a57281c84f2355ae8639b Mon Sep 17 00:00:00 2001 From: Stephan Janssen Date: Tue, 17 Dec 2024 21:20:21 +0100 Subject: [PATCH 1/2] Moved LocalChatModelFactory to correct package. --- .../devoxx/genie/chatmodel/ChatModelProvider.java | 13 ++----------- .../{ => local}/LocalChatModelFactory.java | 3 ++- .../local/gpt4all/GPT4AllChatModelFactory.java | 2 +- .../chatmodel/local/jan/JanChatModelFactory.java | 2 +- .../local/lmstudio/LMStudioChatModelFactory.java | 2 +- .../local/ollama/OllamaChatModelFactory.java | 2 +- 6 files changed, 8 insertions(+), 16 deletions(-) rename src/main/java/com/devoxx/genie/chatmodel/{ => local}/LocalChatModelFactory.java (98%) diff --git a/src/main/java/com/devoxx/genie/chatmodel/ChatModelProvider.java b/src/main/java/com/devoxx/genie/chatmodel/ChatModelProvider.java index 9c2076e..e07be25 100644 --- a/src/main/java/com/devoxx/genie/chatmodel/ChatModelProvider.java +++ b/src/main/java/com/devoxx/genie/chatmodel/ChatModelProvider.java @@ -1,6 +1,5 @@ package com.devoxx.genie.chatmodel; -import com.devoxx.genie.chatmodel.local.lmstudio.LMStudioChatModelFactory; import com.devoxx.genie.model.ChatModel; import com.devoxx.genie.model.Constant; import com.devoxx.genie.model.LanguageModel; @@ -20,19 +19,11 @@ @Setter public class ChatModelProvider { - private static final ModelProvider DEFAULT_PROVIDER = ModelProvider.OpenAI; // Choose an appropriate default + private static final ModelProvider DEFAULT_PROVIDER = ModelProvider.OpenAI; public ChatLanguageModel getChatLanguageModel(@NotNull ChatMessageContext chatMessageContext) { ChatModel chatModel = initChatModel(chatMessageContext); - ChatModelFactory factory = getFactory(chatMessageContext); - - if (factory instanceof LMStudioChatModelFactory) { - if (factory.getModels().isEmpty()) { - throw new IllegalStateException("LMStudio is not running. Please start it and try again."); - } - } - - return factory.createChatModel(chatModel); + return getFactory(chatMessageContext).createChatModel(chatModel); } public StreamingChatLanguageModel getStreamingChatLanguageModel(@NotNull ChatMessageContext chatMessageContext) { diff --git a/src/main/java/com/devoxx/genie/chatmodel/LocalChatModelFactory.java b/src/main/java/com/devoxx/genie/chatmodel/local/LocalChatModelFactory.java similarity index 98% rename from src/main/java/com/devoxx/genie/chatmodel/LocalChatModelFactory.java rename to src/main/java/com/devoxx/genie/chatmodel/local/LocalChatModelFactory.java index bca8d13..fae7832 100644 --- a/src/main/java/com/devoxx/genie/chatmodel/LocalChatModelFactory.java +++ b/src/main/java/com/devoxx/genie/chatmodel/local/LocalChatModelFactory.java @@ -1,5 +1,6 @@ -package com.devoxx.genie.chatmodel; +package com.devoxx.genie.chatmodel.local; +import com.devoxx.genie.chatmodel.ChatModelFactory; import com.devoxx.genie.model.ChatModel; import com.devoxx.genie.model.LanguageModel; import com.devoxx.genie.model.enumarations.ModelProvider; diff --git a/src/main/java/com/devoxx/genie/chatmodel/local/gpt4all/GPT4AllChatModelFactory.java b/src/main/java/com/devoxx/genie/chatmodel/local/gpt4all/GPT4AllChatModelFactory.java index aef0ea9..0314f5f 100644 --- a/src/main/java/com/devoxx/genie/chatmodel/local/gpt4all/GPT4AllChatModelFactory.java +++ b/src/main/java/com/devoxx/genie/chatmodel/local/gpt4all/GPT4AllChatModelFactory.java @@ -1,6 +1,6 @@ package com.devoxx.genie.chatmodel.local.gpt4all; -import com.devoxx.genie.chatmodel.LocalChatModelFactory; +import com.devoxx.genie.chatmodel.local.LocalChatModelFactory; import com.devoxx.genie.model.ChatModel; import com.devoxx.genie.model.LanguageModel; import com.devoxx.genie.model.enumarations.ModelProvider; diff --git a/src/main/java/com/devoxx/genie/chatmodel/local/jan/JanChatModelFactory.java b/src/main/java/com/devoxx/genie/chatmodel/local/jan/JanChatModelFactory.java index af0fe47..ac44fa1 100644 --- a/src/main/java/com/devoxx/genie/chatmodel/local/jan/JanChatModelFactory.java +++ b/src/main/java/com/devoxx/genie/chatmodel/local/jan/JanChatModelFactory.java @@ -1,6 +1,6 @@ package com.devoxx.genie.chatmodel.local.jan; -import com.devoxx.genie.chatmodel.LocalChatModelFactory; +import com.devoxx.genie.chatmodel.local.LocalChatModelFactory; import com.devoxx.genie.model.ChatModel; import com.devoxx.genie.model.LanguageModel; import com.devoxx.genie.model.enumarations.ModelProvider; diff --git a/src/main/java/com/devoxx/genie/chatmodel/local/lmstudio/LMStudioChatModelFactory.java b/src/main/java/com/devoxx/genie/chatmodel/local/lmstudio/LMStudioChatModelFactory.java index ac51e2b..93db5fa 100644 --- a/src/main/java/com/devoxx/genie/chatmodel/local/lmstudio/LMStudioChatModelFactory.java +++ b/src/main/java/com/devoxx/genie/chatmodel/local/lmstudio/LMStudioChatModelFactory.java @@ -1,6 +1,6 @@ package com.devoxx.genie.chatmodel.local.lmstudio; -import com.devoxx.genie.chatmodel.LocalChatModelFactory; +import com.devoxx.genie.chatmodel.local.LocalChatModelFactory; import com.devoxx.genie.model.ChatModel; import com.devoxx.genie.model.LanguageModel; import com.devoxx.genie.model.enumarations.ModelProvider; diff --git a/src/main/java/com/devoxx/genie/chatmodel/local/ollama/OllamaChatModelFactory.java b/src/main/java/com/devoxx/genie/chatmodel/local/ollama/OllamaChatModelFactory.java index b9455d3..41f2400 100644 --- a/src/main/java/com/devoxx/genie/chatmodel/local/ollama/OllamaChatModelFactory.java +++ b/src/main/java/com/devoxx/genie/chatmodel/local/ollama/OllamaChatModelFactory.java @@ -1,6 +1,6 @@ package com.devoxx.genie.chatmodel.local.ollama; -import com.devoxx.genie.chatmodel.LocalChatModelFactory; +import com.devoxx.genie.chatmodel.local.LocalChatModelFactory; import com.devoxx.genie.model.ChatModel; import com.devoxx.genie.model.LanguageModel; import com.devoxx.genie.model.enumarations.ModelProvider; From 6e498a5c5e2c36bedb426e8e83b543b677da01e6 Mon Sep 17 00:00:00 2001 From: Stephan Janssen Date: Tue, 17 Dec 2024 21:25:43 +0100 Subject: [PATCH 2/2] Removed obsolete validation check --- .../java/com/devoxx/genie/chatmodel/ChatModelProvider.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/devoxx/genie/chatmodel/ChatModelProvider.java b/src/main/java/com/devoxx/genie/chatmodel/ChatModelProvider.java index e07be25..08f455e 100644 --- a/src/main/java/com/devoxx/genie/chatmodel/ChatModelProvider.java +++ b/src/main/java/com/devoxx/genie/chatmodel/ChatModelProvider.java @@ -1,5 +1,9 @@ package com.devoxx.genie.chatmodel; +import com.devoxx.genie.chatmodel.local.gpt4all.GPT4AllChatModelFactory; +import com.devoxx.genie.chatmodel.local.jan.JanChatModelFactory; +import com.devoxx.genie.chatmodel.local.lmstudio.LMStudioChatModelFactory; +import com.devoxx.genie.chatmodel.local.ollama.OllamaChatModelFactory; import com.devoxx.genie.model.ChatModel; import com.devoxx.genie.model.Constant; import com.devoxx.genie.model.LanguageModel;