Updated models with Lombok

This commit is contained in:
Amith Koujalgi 2023-12-14 18:12:06 +05:30
parent 1df8622b32
commit a0d6a5ef97
14 changed files with 60 additions and 321 deletions

View File

@ -49,7 +49,7 @@ jobs:
gpg-passphrase: MAVEN_GPG_PASSPHRASE gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Publish to GitHub Packages Apache Maven - name: Publish to GitHub Packages Apache Maven
run: mvn clean deploy -Dgpg.passphrase="${{ secrets.GPG_PASSPHRASE }}" run: mvn clean deploy -Punit-tests -Dgpg.passphrase="${{ secrets.GPG_PASSPHRASE }}"
env: env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}

View File

@ -18,6 +18,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version> <maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
<maven-failsafe-plugin.version>3.0.0-M5</maven-failsafe-plugin.version> <maven-failsafe-plugin.version>3.0.0-M5</maven-failsafe-plugin.version>
<lombok.version>1.18.30</lombok.version>
</properties> </properties>
<developers> <developers>
@ -143,6 +144,12 @@
</build> </build>
<dependencies> <dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>

View File

@ -276,7 +276,7 @@ public class OllamaAPI {
} else { } else {
OllamaResponseModel ollamaResponseModel = OllamaResponseModel ollamaResponseModel =
Utils.getObjectMapper().readValue(line, OllamaResponseModel.class); Utils.getObjectMapper().readValue(line, OllamaResponseModel.class);
if (!ollamaResponseModel.getDone()) { if (!ollamaResponseModel.isDone()) {
responseBuffer.append(ollamaResponseModel.getResponse()); responseBuffer.append(ollamaResponseModel.getResponse());
} }
} }

View File

@ -3,20 +3,11 @@ package io.github.amithkoujalgi.ollama4j.core.models;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List; import java.util.List;
import lombok.Data;
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Data
public class EmbeddingResponse { public class EmbeddingResponse {
@JsonProperty("embedding") @JsonProperty("embedding")
private List<Double> embedding; private List<Double> embedding;
public EmbeddingResponse() {
}
public List<Double> getEmbedding() {
return embedding;
}
public void setEmbedding(List<Double> embedding) {
this.embedding = embedding;
}
} }

View File

@ -1,15 +1,9 @@
package io.github.amithkoujalgi.ollama4j.core.models; package io.github.amithkoujalgi.ollama4j.core.models;
import java.util.List; import java.util.List;
import lombok.Data;
@Data
public class ListModelsResponse { public class ListModelsResponse {
private List<Model> models; private List<Model> models;
public List<Model> getModels() {
return models;
}
public void setModels(List<Model> models) {
this.models = models;
}
} }

View File

@ -1,7 +1,9 @@
package io.github.amithkoujalgi.ollama4j.core.models; package io.github.amithkoujalgi.ollama4j.core.models;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class Model { public class Model {
private String name; private String name;
@ -12,19 +14,6 @@ public class Model {
@JsonProperty("details") @JsonProperty("details")
private ModelMeta modelMeta; private ModelMeta modelMeta;
/**
* 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) {
this.name = name;
}
/** /**
* Returns the model name without its version * Returns the model name without its version
@ -44,31 +33,4 @@ public class Model {
return name.split(":")[1]; return name.split(":")[1];
} }
public String getModifiedAt() {
return modifiedAt;
}
public void setModifiedAt(String modifiedAt) {
this.modifiedAt = modifiedAt;
}
public String getDigest() {
return digest;
}
public void setDigest(String digest) {
this.digest = digest;
}
public long getSize() {
return size;
}
public void setSize(long size) {
this.size = size;
}
public ModelMeta getModelMeta() {
return modelMeta;
}
} }

View File

@ -1,51 +1,14 @@
package io.github.amithkoujalgi.ollama4j.core.models; package io.github.amithkoujalgi.ollama4j.core.models;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class ModelDetail { public class ModelDetail {
private String license; private String license;
@JsonProperty("modelfile") @JsonProperty("modelfile")
private String modelFile; private String modelFile;
private String parameters, template; private String parameters;
private String template;
private String system; private String system;
public String getSystem() {
return system;
}
public void setSystem(String system) {
this.system = system;
}
public String getLicense() {
return license;
}
public void setLicense(String license) {
this.license = license;
}
public String getModelFile() {
return modelFile;
}
public void setModelFile(String modelFile) {
this.modelFile = modelFile;
}
public String getParameters() {
return parameters;
}
public void setParameters(String parameters) {
this.parameters = parameters;
}
public String getTemplate() {
return template;
}
public void setTemplate(String template) {
this.template = template;
}
} }

View File

@ -1,9 +1,12 @@
package io.github.amithkoujalgi.ollama4j.core.models; package io.github.amithkoujalgi.ollama4j.core.models;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class ModelMeta { public class ModelMeta {
@JsonProperty("format") @JsonProperty("format")
private String format; private String format;
@ -18,44 +21,4 @@ public class ModelMeta {
@JsonProperty("quantization_level") @JsonProperty("quantization_level")
private String quantizationLevel; 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;
}
} }

View File

@ -1,44 +1,13 @@
package io.github.amithkoujalgi.ollama4j.core.models; package io.github.amithkoujalgi.ollama4j.core.models;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
@Data
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class ModelPullResponse { public class ModelPullResponse {
private String status; private String status;
private String digest; private String digest;
private long total; private long total;
private long completed; private long completed;
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getDigest() {
return digest;
}
public void setDigest(String digest) {
this.digest = digest;
}
public long getTotal() {
return total;
}
public void setTotal(long total) {
this.total = total;
}
public long getCompleted() {
return completed;
}
public void setCompleted(long completed) {
this.completed = completed;
}
} }

View File

@ -68,12 +68,11 @@ public class OllamaAsyncResultCallback extends Thread {
OllamaResponseModel ollamaResponseModel = OllamaResponseModel ollamaResponseModel =
Utils.getObjectMapper().readValue(line, OllamaResponseModel.class); Utils.getObjectMapper().readValue(line, OllamaResponseModel.class);
queue.add(ollamaResponseModel.getResponse()); queue.add(ollamaResponseModel.getResponse());
if (!ollamaResponseModel.getDone()) { if (!ollamaResponseModel.isDone()) {
responseBuffer.append(ollamaResponseModel.getResponse()); responseBuffer.append(ollamaResponseModel.getResponse());
} }
} }
} }
reader.close();
this.isDone = true; this.isDone = true;
this.succeeded = true; this.succeeded = true;

View File

@ -3,16 +3,11 @@ package io.github.amithkoujalgi.ollama4j.core.models;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List; import java.util.List;
import lombok.Data;
@Data
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class OllamaErrorResponseModel { public class OllamaErrorResponseModel {
private String error; private String error;
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
} }

View File

@ -1,6 +1,9 @@
package io.github.amithkoujalgi.ollama4j.core.models; package io.github.amithkoujalgi.ollama4j.core.models;
import lombok.Data;
@Data
public class OllamaRequestModel { public class OllamaRequestModel {
private String model; private String model;
private String prompt; private String prompt;
@ -9,20 +12,4 @@ public class OllamaRequestModel {
this.model = model; this.model = model;
this.prompt = prompt; this.prompt = prompt;
} }
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getPrompt() {
return prompt;
}
public void setPrompt(String prompt) {
this.prompt = prompt;
}
} }

View File

@ -4,7 +4,9 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List; import java.util.List;
import lombok.Data;
@Data
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class OllamaResponseModel { public class OllamaResponseModel {
private String model; private String model;
@ -18,92 +20,4 @@ public class OllamaResponseModel {
private @JsonProperty("eval_duration") Long evalDuration; private @JsonProperty("eval_duration") Long evalDuration;
private @JsonProperty("prompt_eval_count") Integer promptEvalCount; private @JsonProperty("prompt_eval_count") Integer promptEvalCount;
private @JsonProperty("eval_count") Integer evalCount; private @JsonProperty("eval_count") Integer evalCount;
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
public String getResponse() {
return response;
}
public void setResponse(String response) {
this.response = response;
}
public boolean getDone() {
return done;
}
public void setDone(boolean done) {
this.done = done;
}
public List<Integer> getContext() {
return context;
}
public void setContext(List<Integer> context) {
this.context = context;
}
public Long getTotalDuration() {
return totalDuration;
}
public void setTotalDuration(Long totalDuration) {
this.totalDuration = totalDuration;
}
public Long getLoadDuration() {
return loadDuration;
}
public void setLoadDuration(Long loadDuration) {
this.loadDuration = loadDuration;
}
public Long getPromptEvalDuration() {
return promptEvalDuration;
}
public void setPromptEvalDuration(Long promptEvalDuration) {
this.promptEvalDuration = promptEvalDuration;
}
public Long getEvalDuration() {
return evalDuration;
}
public void setEvalDuration(Long evalDuration) {
this.evalDuration = evalDuration;
}
public Integer getPromptEvalCount() {
return promptEvalCount;
}
public void setPromptEvalCount(Integer promptEvalCount) {
this.promptEvalCount = promptEvalCount;
}
public Integer getEvalCount() {
return evalCount;
}
public void setEvalCount(Integer eval_count) {
this.evalCount = eval_count;
}
} }

View File

@ -3,14 +3,36 @@ package io.github.amithkoujalgi.ollama4j.core.models;
import static io.github.amithkoujalgi.ollama4j.core.utils.Utils.getObjectMapper; import static io.github.amithkoujalgi.ollama4j.core.utils.Utils.getObjectMapper;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.Data;
import lombok.Getter;
/** The type Ollama result. */ /** The type Ollama result. */
@Getter
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Data
public class OllamaResult { public class OllamaResult {
/**
* -- GETTER --
* Get the response text
*
* @return String - response text
*/
private final String response; private final String response;
/**
* -- GETTER --
* Get the response status code.
*
* @return int - response status code
*/
private int httpStatusCode; private int httpStatusCode;
/**
* -- GETTER --
* Get the response time in milliseconds.
*
* @return long - response time in milliseconds
*/
private long responseTime = 0; private long responseTime = 0;
public OllamaResult(String response, long responseTime, int httpStatusCode) { public OllamaResult(String response, long responseTime, int httpStatusCode) {
@ -19,33 +41,6 @@ public class OllamaResult {
this.httpStatusCode = httpStatusCode; this.httpStatusCode = httpStatusCode;
} }
/**
* Get the response text
*
* @return String - response text
*/
public String getResponse() {
return response;
}
/**
* Get the response time in milliseconds.
*
* @return long - response time in milliseconds
*/
public long getResponseTime() {
return responseTime;
}
/**
* Get the response status code.
*
* @return int - response status code
*/
public int getHttpStatusCode() {
return httpStatusCode;
}
@Override @Override
public String toString() { public String toString() {
try { try {