-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #407 from devoxx/issue-406
Feat #406 : Getting local models is now centralised LocalChatModelFac…
- Loading branch information
Showing
51 changed files
with
309 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/devoxx/genie/chatmodel/ChatModelProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../anthropic/AnthropicChatModelFactory.java → .../anthropic/AnthropicChatModelFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...reopenai/AzureOpenAIChatModelFactory.java → ...reopenai/AzureOpenAIChatModelFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../deepinfra/DeepInfraChatModelFactory.java → .../deepinfra/DeepInfraChatModelFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...el/deepseek/DeepSeekChatModelFactory.java → ...ud/deepseek/DeepSeekChatModelFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tmodel/google/GoogleChatModelFactory.java → .../cloud/google/GoogleChatModelFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../chatmodel/groq/GroqChatModelFactory.java → ...odel/cloud/groq/GroqChatModelFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...odel/mistral/MistralChatModelFactory.java → ...loud/mistral/MistralChatModelFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tmodel/openai/OpenAIChatModelFactory.java → .../cloud/openai/OpenAIChatModelFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...penrouter/OpenRouterChatModelFactory.java → ...penrouter/OpenRouterChatModelFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/com/devoxx/genie/chatmodel/local/LocalLLMProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.devoxx.genie.chatmodel.local; | ||
|
||
import java.io.IOException; | ||
|
||
public interface LocalLLMProvider { | ||
Object getModels() throws IOException; | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/com/devoxx/genie/chatmodel/local/LocalLLMProviderUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.devoxx.genie.chatmodel.local; | ||
|
||
import com.devoxx.genie.model.lmstudio.LMStudioModelEntryDTO; | ||
import com.devoxx.genie.service.exception.UnsuccessfulRequestException; | ||
import com.devoxx.genie.ui.settings.DevoxxGenieStateService; | ||
import com.google.gson.Gson; | ||
import com.google.gson.JsonElement; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import static com.devoxx.genie.util.HttpUtil.ensureEndsWithSlash; | ||
|
||
public class LocalLLMProviderUtil { | ||
|
||
private static final OkHttpClient client = new OkHttpClient(); | ||
private static final Gson gson = new Gson(); | ||
|
||
public static <T> T getModels(String baseUrlConfigKey, String endpoint, Class<T> responseType) throws IOException { | ||
String configValue = DevoxxGenieStateService.getInstance().getConfigValue(baseUrlConfigKey); | ||
String baseUrl = ensureEndsWithSlash(Objects.requireNonNull(configValue)); | ||
|
||
Request request = new Request.Builder() | ||
.url(baseUrl + endpoint) | ||
.build(); | ||
|
||
try (Response response = client.newCall(request).execute()) { | ||
if (!response.isSuccessful()) { | ||
throw new UnsuccessfulRequestException("Unexpected code " + response); | ||
} | ||
|
||
if (response.body() == null) { | ||
throw new UnsuccessfulRequestException("Response body is null"); | ||
} | ||
|
||
String json = response.body().string(); | ||
|
||
// Special handling for LM Studio | ||
if (responseType.equals(LMStudioModelEntryDTO[].class)) { | ||
JsonElement jsonElement = gson.fromJson(json, JsonElement.class); | ||
if (jsonElement.isJsonObject() && jsonElement.getAsJsonObject().has("data")) { | ||
return gson.fromJson(jsonElement.getAsJsonObject().get("data"), responseType); | ||
} else { | ||
return responseType.cast(new LMStudioModelEntryDTO[0]); | ||
} | ||
} | ||
|
||
return gson.fromJson(json, responseType); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...mopenai/CustomOpenAIChatModelFactory.java → ...mopenai/CustomOpenAIChatModelFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/com/devoxx/genie/chatmodel/local/gpt4all/GPT4AllModelService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.devoxx.genie.chatmodel.local.gpt4all; | ||
|
||
import com.devoxx.genie.chatmodel.local.LocalLLMProvider; | ||
import com.devoxx.genie.chatmodel.local.LocalLLMProviderUtil; | ||
import com.devoxx.genie.model.gpt4all.Model; | ||
import com.devoxx.genie.model.gpt4all.ResponseDTO; | ||
import com.intellij.openapi.application.ApplicationManager; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class GPT4AllModelService implements LocalLLMProvider { | ||
|
||
@NotNull | ||
public static GPT4AllModelService getInstance() { | ||
return ApplicationManager.getApplication().getService(GPT4AllModelService.class); | ||
} | ||
|
||
@Override | ||
public List<Model> getModels() throws IOException { | ||
return LocalLLMProviderUtil | ||
.getModels("gpt4allModelUrl", "models", ResponseDTO.class) | ||
.getData(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/com/devoxx/genie/chatmodel/local/jan/JanModelService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.devoxx.genie.chatmodel.local.jan; | ||
|
||
import com.devoxx.genie.chatmodel.local.LocalLLMProvider; | ||
import com.devoxx.genie.chatmodel.local.LocalLLMProviderUtil; | ||
import com.devoxx.genie.model.jan.Data; | ||
import com.devoxx.genie.model.jan.ResponseDTO; | ||
import com.intellij.openapi.application.ApplicationManager; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class JanModelService implements LocalLLMProvider { | ||
|
||
@NotNull | ||
public static JanModelService getInstance() { | ||
return ApplicationManager.getApplication().getService(JanModelService.class); | ||
} | ||
|
||
@Override | ||
public List<Data> getModels() throws IOException { | ||
return LocalLLMProviderUtil | ||
.getModels("janModelUrl", "models", ResponseDTO.class) | ||
.getData(); | ||
} | ||
} |
Oops, something went wrong.