diff --git a/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/GetOllamaModelsResponse.java b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/GetOllamaModelsResponse.java new file mode 100644 index 0000000..4586e14 --- /dev/null +++ b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/GetOllamaModelsResponse.java @@ -0,0 +1,20 @@ +package com.developer.nefarious.zjoule.plugin.login.api; + +import java.util.List; + +import com.developer.nefarious.zjoule.plugin.models.OllamaModel; + +public class GetOllamaModelsResponse { + + private List models; + + // Getters and Setters + public List getModels() { + return models; + } + + public void setModels(final List models) { + this.models = models; + } + +} diff --git a/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/IOllamaLoginClient.java b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/IOllamaLoginClient.java new file mode 100644 index 0000000..b016f6b --- /dev/null +++ b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/IOllamaLoginClient.java @@ -0,0 +1,7 @@ +package com.developer.nefarious.zjoule.plugin.login.api; + +public interface IOllamaLoginClient { + + GetOllamaModelsResponse getModels(); + +} diff --git a/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/IOllamaLoginClientHelper.java b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/IOllamaLoginClientHelper.java new file mode 100644 index 0000000..2a9ac1c --- /dev/null +++ b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/IOllamaLoginClientHelper.java @@ -0,0 +1,11 @@ +package com.developer.nefarious.zjoule.plugin.login.api; + +import java.net.URI; + +public interface IOllamaLoginClientHelper { + + URI createUri(final String endpoint); + + GetOllamaModelsResponse parseOllamaModelsResponseToObject(final String responseBody); + +} diff --git a/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/OllamaLoginClient.java b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/OllamaLoginClient.java new file mode 100644 index 0000000..a014830 --- /dev/null +++ b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/OllamaLoginClient.java @@ -0,0 +1,11 @@ +package com.developer.nefarious.zjoule.plugin.login.api; + +public class OllamaLoginClient implements IOllamaLoginClient { + + @Override + public GetOllamaModelsResponse getModels() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/OllamaLoginClientHelper.java b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/OllamaLoginClientHelper.java new file mode 100644 index 0000000..a711cce --- /dev/null +++ b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/OllamaLoginClientHelper.java @@ -0,0 +1,25 @@ +package com.developer.nefarious.zjoule.plugin.login.api; + +import java.net.URI; + +import com.google.gson.Gson; + +public class OllamaLoginClientHelper implements IOllamaLoginClientHelper { + + private Gson gson; + + public OllamaLoginClientHelper() { + gson = new Gson(); + } + + @Override + public URI createUri(final String endpoint) { + return URI.create(endpoint); + } + + @Override + public GetOllamaModelsResponse parseOllamaModelsResponseToObject(final String responseBody) { + return gson.fromJson(responseBody, GetOllamaModelsResponse.class); + } + +} diff --git a/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/pages/SecondOllamaLoginPage.java b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/pages/SecondOllamaLoginPage.java index 566a3dd..4179b4a 100644 --- a/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/pages/SecondOllamaLoginPage.java +++ b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/pages/SecondOllamaLoginPage.java @@ -28,7 +28,7 @@ public SecondOllamaLoginPage() { } @Override - public void createControl(Composite parent) { + public void createControl(final Composite parent) { Composite container = new Composite(parent, SWT.NONE); container.setLayout(new GridLayout(2, false)); @@ -46,7 +46,7 @@ private void selectModel() { setPageComplete(true); } - public void setModelsForSelection(List modelsForSelection) { + public void setModelsForSelection(final List modelsForSelection) { modelDropdown.setItems(modelsForSelection.toArray(new String[0])); } diff --git a/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/models/OllamaModel.java b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/models/OllamaModel.java new file mode 100644 index 0000000..df098a5 --- /dev/null +++ b/com.developer.nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/models/OllamaModel.java @@ -0,0 +1,138 @@ +package com.developer.nefarious.zjoule.plugin.models; + +import java.util.List; + +import com.google.gson.annotations.SerializedName; + +public class OllamaModel { + + private String name; + + private String model; + + @SerializedName("modified_at") + private String modifiedAt; + + private long size; + + private String digest; + + private OllamaModelDetails details; + + // Getters and Setters + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getModel() { + return model; + } + + public void setModel(final String model) { + this.model = model; + } + + public String getModifiedAt() { + return modifiedAt; + } + + public void setModifiedAt(final String modifiedAt) { + this.modifiedAt = modifiedAt; + } + + public long getSize() { + return size; + } + + public void setSize(final long size) { + this.size = size; + } + + public String getDigest() { + return digest; + } + + public void setDigest(final String digest) { + this.digest = digest; + } + + public OllamaModelDetails getDetails() { + return details; + } + + public void setDetails(final OllamaModelDetails details) { + this.details = details; + } + +} + +class OllamaModelDetails { + + @SerializedName("parent_model") + private String parentModel; + + private String format; + + private String family; + + private List families; + + @SerializedName("parameter_size") + private String parameterSize; + + @SerializedName("quantization_level") + private String quantizationLevel; + + // Getters and Setters + public String getParentModel() { + return parentModel; + } + + public void setParentModel(final String parentModel) { + this.parentModel = parentModel; + } + + public String getFormat() { + return format; + } + + public void setFormat(final String format) { + this.format = format; + } + + public String getFamily() { + return family; + } + + public void setFamily(final String family) { + this.family = family; + } + + public List getFamilies() { + return families; + } + + public void setFamilies(final List families) { + this.families = families; + } + + public String getParameterSize() { + return parameterSize; + } + + public void setParameterSize(final String parameterSize) { + this.parameterSize = parameterSize; + } + + public String getQuantizationLevel() { + return quantizationLevel; + } + + public void setQuantizationLevel(final String quantizationLevel) { + this.quantizationLevel = quantizationLevel; + } +} diff --git a/com.developer.nefarious.zjoule.test/src/com/developer/nefarious/zjoule/test/login/api/OllamaLoginClientHelperTest.java b/com.developer.nefarious.zjoule.test/src/com/developer/nefarious/zjoule/test/login/api/OllamaLoginClientHelperTest.java new file mode 100644 index 0000000..583cf21 --- /dev/null +++ b/com.developer.nefarious.zjoule.test/src/com/developer/nefarious/zjoule/test/login/api/OllamaLoginClientHelperTest.java @@ -0,0 +1,59 @@ +package com.developer.nefarious.zjoule.test.login.api; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; + +import java.net.URI; +import java.util.concurrent.ThreadLocalRandom; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.MockedStatic; + +import com.developer.nefarious.zjoule.plugin.login.api.GetOllamaModelsResponse; +import com.developer.nefarious.zjoule.plugin.login.api.OllamaLoginClientHelper; +import com.google.gson.Gson; + +public class OllamaLoginClientHelperTest { + + private OllamaLoginClientHelper cut; + + private String randomWord() { + final String[] WORDS = { "apple", "banana", "grape" }; + int randomIndex = ThreadLocalRandom.current().nextInt(WORDS.length); + return WORDS[randomIndex]; + } + + @BeforeEach + public void setUp() { + cut = new OllamaLoginClientHelper(); + } + + @Test + public void shouldConvertTheModelsResponseBodyToObject() { + // Arrange + Gson gson = new Gson(); + String mockResponseBody = "{\"models\": [{\"name\": \"llama3.2:latest\"}]}"; + GetOllamaModelsResponse expectedObject = gson.fromJson(mockResponseBody, GetOllamaModelsResponse.class); + // Act + GetOllamaModelsResponse returnObject = cut.parseOllamaModelsResponseToObject(mockResponseBody); + // Assert + assertEquals(returnObject.getModels().getFirst().getName(), expectedObject.getModels().getFirst().getName()); + } + + @Test + public void shouldCreateTheUri() { + // Arrange + URI expectedObject = mock(URI.class); + String mockEndpoint = randomWord(); + try (MockedStatic uriStatic = mockStatic(URI.class)) { + uriStatic.when(() -> URI.create(mockEndpoint)).thenReturn(expectedObject); + // Act + URI returnObject = cut.createUri(mockEndpoint); + // Assert + assertEquals(returnObject, expectedObject); + } + } + +}