Updated models with @JsonProperty to have Java-naming conventions for attributes

This commit is contained in:
Amith Koujalgi 2023-11-12 20:00:44 +05:30
parent 5c5463b764
commit 48acf921e8
4 changed files with 100 additions and 35 deletions

View File

@ -307,20 +307,19 @@ Find the full `Javadoc` (API specifications) [here](https://amithkoujalgi.github
#### Areas of improvement #### 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`) possibly with Jackson-mapper's `@JsonProperty`)
- Fix deprecated HTTP client code - [ ] Fix deprecated HTTP client code
- Add additional params for `ask` APIs such as: - [ ] Add additional params for `ask` APIs such as:
- `options`: additional model parameters for the Modelfile such as `temperature` - `options`: additional model parameters for the Modelfile such as `temperature`
- `system`: system prompt to (overrides what is defined in the Modelfile) - `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) - `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 - `context`: the context parameter returned from a previous request, which can be used to keep a short
conversational memory conversational memory
- `stream`: Add support for streaming responses from the model - `stream`: Add support for streaming responses from the model
- [x] Setup logging
- Setup logging - [ ] Add test cases
- Add test cases - [ ] Handle exceptions better (maybe throw more appropriate exceptions)
- Handle exceptions better (maybe throw more appropriate exceptions)
#### Get Involved #### Get Involved

View File

@ -1,7 +1,12 @@
package io.github.amithkoujalgi.ollama4j.core.models; package io.github.amithkoujalgi.ollama4j.core.models;
import com.fasterxml.jackson.annotation.JsonProperty;
public class Model { public class Model {
private String name, modified_at, digest; private String name;
@JsonProperty("modified_at")
private String modifiedAt;
private String digest;
private Long size; private Long size;
/** /**
@ -32,12 +37,12 @@ public class Model {
this.name = name; this.name = name;
} }
public String getModified_at() { public String getModifiedAt() {
return modified_at; return modifiedAt;
} }
public void setModified_at(String modified_at) { public void setModifiedAt(String modifiedAt) {
this.modified_at = modified_at; this.modifiedAt = modifiedAt;
} }
public String getDigest() { public String getDigest() {

View File

@ -1,10 +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.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
public class ModelDetail { public class ModelDetail {
private String license, modelfile, parameters, template; private String license;
@JsonProperty("modelfile")
private String modelFile;
private String parameters, template;
public String getLicense() { public String getLicense() {
return license; return license;
@ -14,12 +18,12 @@ public class ModelDetail {
this.license = license; this.license = license;
} }
public String getModelfile() { public String getModelFile() {
return modelfile; return modelFile;
} }
public void setModelfile(String modelfile) { public void setModelFile(String modelFile) {
this.modelfile = modelfile; this.modelFile = modelFile;
} }
public String getParameters() { public String getParameters() {

View File

@ -1,61 +1,118 @@
package io.github.amithkoujalgi.ollama4j.core.models; package io.github.amithkoujalgi.ollama4j.core.models;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List; import java.util.List;
public class OllamaResponseModel { public class OllamaResponseModel {
private String model; private String model;
private String created_at; @JsonProperty("created_at")
private String createdAt;
private String response; private String response;
private Boolean done; private Boolean done;
private List<Integer> context; private List<Integer> context;
private Long total_duration; @JsonProperty("total_duration")
private Long load_duration; private Long totalDuration;
private Long prompt_eval_duration;
private Long eval_duration; @JsonProperty("load_duration")
private Integer prompt_eval_count; 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; private Integer eval_count;
public String getModel() { public String getModel() {
return model; return model;
} }
public String getCreated_at() { public void setModel(String model) {
return created_at; this.model = model;
}
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
} }
public String getResponse() { public String getResponse() {
return response; return response;
} }
public void setResponse(String response) {
this.response = response;
}
public Boolean getDone() { public Boolean getDone() {
return done; return done;
} }
public void setDone(Boolean done) {
this.done = done;
}
public List<Integer> getContext() { public List<Integer> getContext() {
return context; return context;
} }
public Long getTotal_duration() { public void setContext(List<Integer> context) {
return total_duration; this.context = context;
} }
public Long getLoad_duration() { public Long getTotalDuration() {
return load_duration; return totalDuration;
} }
public Long getPrompt_eval_duration() { public void setTotalDuration(Long totalDuration) {
return prompt_eval_duration; this.totalDuration = totalDuration;
} }
public Long getEval_duration() { public Long getLoadDuration() {
return eval_duration; return loadDuration;
} }
public Integer getPrompt_eval_count() { public void setLoadDuration(Long loadDuration) {
return prompt_eval_count; 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() { public Integer getEval_count() {
return eval_count; return eval_count;
} }
public void setEval_count(Integer eval_count) {
this.eval_count = eval_count;
}
} }