From 48acf921e86828462f11cce04b7cc9118aa12237 Mon Sep 17 00:00:00 2001 From: Amith Koujalgi Date: Sun, 12 Nov 2023 20:00:44 +0530 Subject: [PATCH] Updated models with `@JsonProperty` to have Java-naming conventions for attributes --- README.md | 13 ++- .../ollama4j/core/models/Model.java | 15 ++- .../ollama4j/core/models/ModelDetail.java | 14 ++- .../core/models/OllamaResponseModel.java | 93 +++++++++++++++---- 4 files changed, 100 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 325d232..c370adc 100644 --- a/README.md +++ b/README.md @@ -307,20 +307,19 @@ Find the full `Javadoc` (API specifications) [here](https://amithkoujalgi.github #### Areas of improvement -- Use Java-naming conventions for attributes in the request/response models instead of the snake-case conventions. ( +- [x] Use Java-naming conventions for attributes in the request/response models instead of the snake-case conventions. ( possibly with Jackson-mapper's `@JsonProperty`) -- Fix deprecated HTTP client code -- Add additional params for `ask` APIs such as: +- [ ] Fix deprecated HTTP client code +- [ ] Add additional params for `ask` APIs such as: - `options`: additional model parameters for the Modelfile such as `temperature` - `system`: system prompt to (overrides what is defined in the Modelfile) - `template`: the full prompt or prompt template (overrides what is defined in the Modelfile) - `context`: the context parameter returned from a previous request, which can be used to keep a short conversational memory - `stream`: Add support for streaming responses from the model - -- Setup logging -- Add test cases -- Handle exceptions better (maybe throw more appropriate exceptions) +- [x] Setup logging +- [ ] Add test cases +- [ ] Handle exceptions better (maybe throw more appropriate exceptions) #### Get Involved diff --git a/src/main/java/io/github/amithkoujalgi/ollama4j/core/models/Model.java b/src/main/java/io/github/amithkoujalgi/ollama4j/core/models/Model.java index 1c8afe0..0ae46e8 100644 --- a/src/main/java/io/github/amithkoujalgi/ollama4j/core/models/Model.java +++ b/src/main/java/io/github/amithkoujalgi/ollama4j/core/models/Model.java @@ -1,7 +1,12 @@ package io.github.amithkoujalgi.ollama4j.core.models; +import com.fasterxml.jackson.annotation.JsonProperty; + public class Model { - private String name, modified_at, digest; + private String name; + @JsonProperty("modified_at") + private String modifiedAt; + private String digest; private Long size; /** @@ -32,12 +37,12 @@ public class Model { this.name = name; } - public String getModified_at() { - return modified_at; + public String getModifiedAt() { + return modifiedAt; } - public void setModified_at(String modified_at) { - this.modified_at = modified_at; + public void setModifiedAt(String modifiedAt) { + this.modifiedAt = modifiedAt; } public String getDigest() { diff --git a/src/main/java/io/github/amithkoujalgi/ollama4j/core/models/ModelDetail.java b/src/main/java/io/github/amithkoujalgi/ollama4j/core/models/ModelDetail.java index e778f67..c0aef49 100644 --- a/src/main/java/io/github/amithkoujalgi/ollama4j/core/models/ModelDetail.java +++ b/src/main/java/io/github/amithkoujalgi/ollama4j/core/models/ModelDetail.java @@ -1,10 +1,14 @@ package io.github.amithkoujalgi.ollama4j.core.models; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; public class ModelDetail { - private String license, modelfile, parameters, template; + private String license; + @JsonProperty("modelfile") + private String modelFile; + private String parameters, template; public String getLicense() { return license; @@ -14,12 +18,12 @@ public class ModelDetail { this.license = license; } - public String getModelfile() { - return modelfile; + public String getModelFile() { + return modelFile; } - public void setModelfile(String modelfile) { - this.modelfile = modelfile; + public void setModelFile(String modelFile) { + this.modelFile = modelFile; } public String getParameters() { diff --git a/src/main/java/io/github/amithkoujalgi/ollama4j/core/models/OllamaResponseModel.java b/src/main/java/io/github/amithkoujalgi/ollama4j/core/models/OllamaResponseModel.java index 082d890..a0ab481 100644 --- a/src/main/java/io/github/amithkoujalgi/ollama4j/core/models/OllamaResponseModel.java +++ b/src/main/java/io/github/amithkoujalgi/ollama4j/core/models/OllamaResponseModel.java @@ -1,61 +1,118 @@ package io.github.amithkoujalgi.ollama4j.core.models; +import com.fasterxml.jackson.annotation.JsonProperty; + import java.util.List; public class OllamaResponseModel { private String model; - private String created_at; + @JsonProperty("created_at") + private String createdAt; private String response; private Boolean done; private List context; - private Long total_duration; - private Long load_duration; - private Long prompt_eval_duration; - private Long eval_duration; - private Integer prompt_eval_count; + @JsonProperty("total_duration") + private Long totalDuration; + + @JsonProperty("load_duration") + private Long loadDuration; + @JsonProperty("prompt_eval_duration") + private Long promptEvalDuration; + @JsonProperty("eval_duration") + + private Long evalDuration; + @JsonProperty("prompt_eval_count") + + private Integer promptEvalCount; + @JsonProperty("evalCount") + private Integer eval_count; public String getModel() { return model; } - public String getCreated_at() { - return created_at; + 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 getContext() { return context; } - public Long getTotal_duration() { - return total_duration; + public void setContext(List context) { + this.context = context; } - public Long getLoad_duration() { - return load_duration; + public Long getTotalDuration() { + return totalDuration; } - public Long getPrompt_eval_duration() { - return prompt_eval_duration; + public void setTotalDuration(Long totalDuration) { + this.totalDuration = totalDuration; } - public Long getEval_duration() { - return eval_duration; + public Long getLoadDuration() { + return loadDuration; } - public Integer getPrompt_eval_count() { - return prompt_eval_count; + 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 getEval_count() { return eval_count; } + + public void setEval_count(Integer eval_count) { + this.eval_count = eval_count; + } }