diff --git a/build.gradle.kts b/build.gradle.kts index d65b6e4e..b0be3dc8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } group = "com.devoxx.genie" -version = "0.2.8" +version = "0.2.9" repositories { mavenCentral() diff --git a/src/main/java/com/devoxx/genie/model/enumarations/ModelProvider.java b/src/main/java/com/devoxx/genie/model/enumarations/ModelProvider.java index 64e1bb62..b88429fd 100644 --- a/src/main/java/com/devoxx/genie/model/enumarations/ModelProvider.java +++ b/src/main/java/com/devoxx/genie/model/enumarations/ModelProvider.java @@ -14,7 +14,7 @@ public enum ModelProvider { Groq("Groq"), DeepInfra("DeepInfra"), Google("Google"), - Exo("Exo"); + Exo("Exo (Experimental)"); private final String name; diff --git a/src/main/java/com/devoxx/genie/service/OllamaApiService.java b/src/main/java/com/devoxx/genie/service/OllamaApiService.java index bca6971e..8b92ab5f 100644 --- a/src/main/java/com/devoxx/genie/service/OllamaApiService.java +++ b/src/main/java/com/devoxx/genie/service/OllamaApiService.java @@ -1,26 +1,36 @@ package com.devoxx.genie.service; +import com.devoxx.genie.ui.settings.DevoxxGenieStateService; import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import okhttp3.*; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import java.io.IOException; public class OllamaApiService { - private static final String OLLAMA_API_URL = "http://localhost:11434/api/show"; private static final OkHttpClient client = new OkHttpClient(); private static final Gson gson = new Gson(); + public static final int DEFAULT_CONTEXT_LENGTH = 4096; + /** + * Get the context length of the model. + * @param modelName the model name + * @return the context length + * @throws IOException if there is an error + */ public static int getModelContext(@NotNull String modelName) throws IOException { RequestBody body = RequestBody.create( MediaType.parse("application/json"), "{\"name\":\"" + modelName + "\"}" ); + String baseUrl = ensureEndsWithSlash(DevoxxGenieStateService.getInstance().getOllamaModelUrl()); + Request request = new Request.Builder() - .url(OLLAMA_API_URL) + .url(DevoxxGenieStateService.getInstance().getOllamaModelUrl()+ "api/show") .post(body) .build(); @@ -49,6 +59,17 @@ private static int findContextLength(@NotNull JsonObject jsonObject) { return contextLength.getAsInt(); } - return -1; // Return -1 if not found + return DEFAULT_CONTEXT_LENGTH; + } + + /** + * Ensure the URL ends with a slash. + * + * @param url the URL + * @return the URL with a slash at the end + */ + @Contract(pure = true) + public static String ensureEndsWithSlash(@NotNull String url) { + return url.endsWith("/") ? url : url + "/"; } } diff --git a/src/main/java/com/devoxx/genie/service/OllamaService.java b/src/main/java/com/devoxx/genie/service/OllamaService.java index 5b751951..595281fe 100644 --- a/src/main/java/com/devoxx/genie/service/OllamaService.java +++ b/src/main/java/com/devoxx/genie/service/OllamaService.java @@ -13,6 +13,8 @@ import java.io.IOException; +import static com.devoxx.genie.service.OllamaApiService.ensureEndsWithSlash; + public class OllamaService { private final OkHttpClient client = new OkHttpClient(); @@ -25,7 +27,7 @@ public static OllamaService getInstance() { /** * Get the models from the Ollama service. * - * @return List of model names + * @return array of model names * @throws IOException if there is an error */ public OllamaModelEntryDTO[] getModels() throws IOException { @@ -47,17 +49,6 @@ public OllamaModelEntryDTO[] getModels() throws IOException { } } - /** - * Ensure the URL ends with a slash. - * - * @param url the URL - * @return the URL with a slash at the end - */ - @Contract(pure = true) - private String ensureEndsWithSlash(@NotNull String url) { - return url.endsWith("/") ? url : url + "/"; - } - /** * Exception for unsuccessful requests. */ diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 65467895..48ac13a4 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -35,6 +35,10 @@ ]]> v0.2.9 +

v0.2.8