forked from Mirror/ollama4j
Fixes to listModels API
This commit is contained in:
parent
b2d76970dc
commit
1df8622b32
@ -3,62 +3,72 @@ package io.github.amithkoujalgi.ollama4j.core.models;
|
|||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
public class Model {
|
public class Model {
|
||||||
private String name;
|
|
||||||
@JsonProperty("modified_at")
|
|
||||||
private String modifiedAt;
|
|
||||||
private String digest;
|
|
||||||
private long size;
|
|
||||||
|
|
||||||
/**
|
private String name;
|
||||||
* Returns the model's tag. This includes model name and its version separated by a colon character `:`
|
@JsonProperty("modified_at")
|
||||||
* @return model tag
|
private String modifiedAt;
|
||||||
*/
|
private String digest;
|
||||||
public String getName() {
|
private long size;
|
||||||
return name;
|
@JsonProperty("details")
|
||||||
}
|
private ModelMeta modelMeta;
|
||||||
|
|
||||||
public void setName(String name) {
|
/**
|
||||||
this.name = name;
|
* Returns the model's tag. This includes model name and its version separated by a colon
|
||||||
}
|
* character `:`
|
||||||
|
*
|
||||||
|
* @return model tag
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public void setName(String name) {
|
||||||
* Returns the model name without its version
|
this.name = name;
|
||||||
* @return model name
|
}
|
||||||
*/
|
|
||||||
public String getModelName() {
|
|
||||||
return name.split(":")[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the model version without its name
|
* Returns the model name without its version
|
||||||
* @return model version
|
*
|
||||||
*/
|
* @return model name
|
||||||
public String getModelVersion() {
|
*/
|
||||||
return name.split(":")[1];
|
public String getModelName() {
|
||||||
}
|
return name.split(":")[0];
|
||||||
|
}
|
||||||
|
|
||||||
public String getModifiedAt() {
|
/**
|
||||||
return modifiedAt;
|
* Returns the model version without its name
|
||||||
}
|
*
|
||||||
|
* @return model version
|
||||||
|
*/
|
||||||
|
public String getModelVersion() {
|
||||||
|
return name.split(":")[1];
|
||||||
|
}
|
||||||
|
|
||||||
public void setModifiedAt(String modifiedAt) {
|
public String getModifiedAt() {
|
||||||
this.modifiedAt = modifiedAt;
|
return modifiedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDigest() {
|
public void setModifiedAt(String modifiedAt) {
|
||||||
return digest;
|
this.modifiedAt = modifiedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDigest(String digest) {
|
public String getDigest() {
|
||||||
this.digest = digest;
|
return digest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getSize() {
|
public void setDigest(String digest) {
|
||||||
return size;
|
this.digest = digest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSize(long size) {
|
public long getSize() {
|
||||||
this.size = size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSize(long size) {
|
||||||
|
this.size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModelMeta getModelMeta() {
|
||||||
|
return modelMeta;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
package io.github.amithkoujalgi.ollama4j.core.models;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
public class ModelMeta {
|
||||||
|
|
||||||
|
@JsonProperty("format")
|
||||||
|
private String format;
|
||||||
|
|
||||||
|
@JsonProperty("family")
|
||||||
|
private String family;
|
||||||
|
|
||||||
|
@JsonProperty("families")
|
||||||
|
private String[] families;
|
||||||
|
|
||||||
|
@JsonProperty("parameter_size")
|
||||||
|
private String parameterSize;
|
||||||
|
|
||||||
|
@JsonProperty("quantization_level")
|
||||||
|
private String quantizationLevel;
|
||||||
|
|
||||||
|
public String getFormat() {
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFormat(String format) {
|
||||||
|
this.format = format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFamily() {
|
||||||
|
return family;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFamily(String family) {
|
||||||
|
this.family = family;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getFamilies() {
|
||||||
|
return families;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFamilies(String[] families) {
|
||||||
|
this.families = families;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getParameterSize() {
|
||||||
|
return parameterSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParameterSize(String parameterSize) {
|
||||||
|
this.parameterSize = parameterSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getQuantizationLevel() {
|
||||||
|
return quantizationLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuantizationLevel(String quantizationLevel) {
|
||||||
|
this.quantizationLevel = quantizationLevel;
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ import io.github.amithkoujalgi.ollama4j.core.models.ModelDetail;
|
|||||||
import io.github.amithkoujalgi.ollama4j.core.models.OllamaAsyncResultCallback;
|
import io.github.amithkoujalgi.ollama4j.core.models.OllamaAsyncResultCallback;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.models.OllamaResult;
|
import io.github.amithkoujalgi.ollama4j.core.models.OllamaResult;
|
||||||
import io.github.amithkoujalgi.ollama4j.core.types.OllamaModelType;
|
import io.github.amithkoujalgi.ollama4j.core.types.OllamaModelType;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
@ -13,109 +14,25 @@ import java.io.IOException;
|
|||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class TestRealAPIs {
|
class TestRealAPIs {
|
||||||
@Test
|
|
||||||
public void testMockPullModel() {
|
|
||||||
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
|
|
||||||
String model = OllamaModelType.LLAMA2;
|
|
||||||
try {
|
|
||||||
doNothing().when(ollamaAPI).pullModel(model);
|
|
||||||
ollamaAPI.pullModel(model);
|
|
||||||
verify(ollamaAPI, times(1)).pullModel(model);
|
|
||||||
} catch (IOException | OllamaBaseException | InterruptedException | URISyntaxException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
OllamaAPI ollamaAPI;
|
||||||
public void testListModels() {
|
|
||||||
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
|
|
||||||
try {
|
|
||||||
when(ollamaAPI.listModels()).thenReturn(new ArrayList<>());
|
|
||||||
ollamaAPI.listModels();
|
|
||||||
verify(ollamaAPI, times(1)).listModels();
|
|
||||||
} catch (IOException | OllamaBaseException | InterruptedException | URISyntaxException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@BeforeEach
|
||||||
public void testCreateModel() {
|
void setUp() {
|
||||||
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
|
String ollamaHost = "http://localhost:11434";
|
||||||
String model = OllamaModelType.LLAMA2;
|
ollamaAPI = new OllamaAPI(ollamaHost);
|
||||||
String modelFilePath = "/somemodel";
|
}
|
||||||
try {
|
|
||||||
doNothing().when(ollamaAPI).createModel(model, modelFilePath);
|
|
||||||
ollamaAPI.createModel(model, modelFilePath);
|
|
||||||
verify(ollamaAPI, times(1)).createModel(model, modelFilePath);
|
|
||||||
} catch (IOException | OllamaBaseException | InterruptedException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteModel() {
|
void testListModels() {
|
||||||
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
|
try {
|
||||||
String model = OllamaModelType.LLAMA2;
|
assertNotNull(ollamaAPI.listModels());
|
||||||
try {
|
} catch (IOException | OllamaBaseException | InterruptedException | URISyntaxException e) {
|
||||||
doNothing().when(ollamaAPI).deleteModel(model, true);
|
throw new RuntimeException(e);
|
||||||
ollamaAPI.deleteModel(model, true);
|
|
||||||
verify(ollamaAPI, times(1)).deleteModel(model, true);
|
|
||||||
} catch (IOException | OllamaBaseException | InterruptedException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetModelDetails() {
|
|
||||||
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
|
|
||||||
String model = OllamaModelType.LLAMA2;
|
|
||||||
try {
|
|
||||||
when(ollamaAPI.getModelDetails(model)).thenReturn(new ModelDetail());
|
|
||||||
ollamaAPI.getModelDetails(model);
|
|
||||||
verify(ollamaAPI, times(1)).getModelDetails(model);
|
|
||||||
} catch (IOException | OllamaBaseException | InterruptedException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGenerateEmbeddings() {
|
|
||||||
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
|
|
||||||
String model = OllamaModelType.LLAMA2;
|
|
||||||
String prompt = "some prompt text";
|
|
||||||
try {
|
|
||||||
when(ollamaAPI.generateEmbeddings(model, prompt)).thenReturn(new ArrayList<>());
|
|
||||||
ollamaAPI.generateEmbeddings(model, prompt);
|
|
||||||
verify(ollamaAPI, times(1)).generateEmbeddings(model, prompt);
|
|
||||||
} catch (IOException | OllamaBaseException | InterruptedException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAsk() {
|
|
||||||
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
|
|
||||||
String model = OllamaModelType.LLAMA2;
|
|
||||||
String prompt = "some prompt text";
|
|
||||||
try {
|
|
||||||
when(ollamaAPI.ask(model, prompt)).thenReturn(new OllamaResult("", 0,200));
|
|
||||||
ollamaAPI.ask(model, prompt);
|
|
||||||
verify(ollamaAPI, times(1)).ask(model, prompt);
|
|
||||||
} catch (IOException | OllamaBaseException | InterruptedException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAskAsync() {
|
|
||||||
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
|
|
||||||
String model = OllamaModelType.LLAMA2;
|
|
||||||
String prompt = "some prompt text";
|
|
||||||
when(ollamaAPI.askAsync(model, prompt)).thenReturn(new OllamaAsyncResultCallback(null, null, null));
|
|
||||||
ollamaAPI.askAsync(model, prompt);
|
|
||||||
verify(ollamaAPI, times(1)).askAsync(model, prompt);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user