-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nickchecan
committed
Jan 16, 2025
1 parent
f8b7e88
commit c170a0d
Showing
8 changed files
with
273 additions
and
2 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
...e.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/GetOllamaModelsResponse.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,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<OllamaModel> models; | ||
|
||
// Getters and Setters | ||
public List<OllamaModel> getModels() { | ||
return models; | ||
} | ||
|
||
public void setModels(final List<OllamaModel> models) { | ||
this.models = models; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/IOllamaLoginClient.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.developer.nefarious.zjoule.plugin.login.api; | ||
|
||
public interface IOllamaLoginClient { | ||
|
||
GetOllamaModelsResponse getModels(); | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
....plugin/src/com/developer/nefarious/zjoule/plugin/login/api/IOllamaLoginClientHelper.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,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); | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
....zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/OllamaLoginClient.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,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; | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...e.plugin/src/com/developer/nefarious/zjoule/plugin/login/api/OllamaLoginClientHelper.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,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); | ||
} | ||
|
||
} |
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
138 changes: 138 additions & 0 deletions
138
...nefarious.zjoule.plugin/src/com/developer/nefarious/zjoule/plugin/models/OllamaModel.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,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<String> 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<String> getFamilies() { | ||
return families; | ||
} | ||
|
||
public void setFamilies(final List<String> 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; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...e.test/src/com/developer/nefarious/zjoule/test/login/api/OllamaLoginClientHelperTest.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,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<URI> uriStatic = mockStatic(URI.class)) { | ||
uriStatic.when(() -> URI.create(mockEndpoint)).thenReturn(expectedObject); | ||
// Act | ||
URI returnObject = cut.createUri(mockEndpoint); | ||
// Assert | ||
assertEquals(returnObject, expectedObject); | ||
} | ||
} | ||
|
||
} |