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
- 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

View File

@ -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() {

View File

@ -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() {

View File

@ -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<Integer> 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<Integer> getContext() {
return context;
}
public Long getTotal_duration() {
return total_duration;
public void setContext(List<Integer> 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;
}
}