Skip to content

Commit

Permalink
Fix #182: Replace fixed URL with Settings URL
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanj committed Jul 26, 2024
1 parent 91c6882 commit 14f71d1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "com.devoxx.genie"
version = "0.2.8"
version = "0.2.9"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum ModelProvider {
Groq("Groq"),
DeepInfra("DeepInfra"),
Google("Google"),
Exo("Exo");
Exo("Exo (Experimental)");

private final String name;

Expand Down
27 changes: 24 additions & 3 deletions src/main/java/com/devoxx/genie/service/OllamaApiService.java
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -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 + "/";
}
}
15 changes: 3 additions & 12 deletions src/main/java/com/devoxx/genie/service/OllamaService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 {
Expand All @@ -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.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
]]></description>

<change-notes><![CDATA[
<h2>v0.2.9</h2>
<UL>
<LI>Fix #183 - Allow usage of remote Ollama instances</LI>
</UL>
<h2>v0.2.8</h2>
<UL>
<LI>Support Exo Local LLM cluster: more info @ https://github.com/exo-explore/exo</LI>
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Wed Jul 24 19:23:27 CEST 2024
version=0.2.7
#Fri Jul 26 12:51:47 CEST 2024
version=0.2.9

0 comments on commit 14f71d1

Please sign in to comment.