1package io.github.ollama4j.models.response;
3import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4import com.fasterxml.jackson.annotation.JsonProperty;
5import com.fasterxml.jackson.core.JsonProcessingException;
6import com.fasterxml.jackson.core.type.TypeReference;
9import lombok.NoArgsConstructor;
14import static io.github.ollama4j.utils.Utils.getObjectMapper;
17@SuppressWarnings(
"unused")
20@JsonIgnoreProperties(ignoreUnknown =
true)
22 private String response;
23 private String thinking;
24 private int httpStatusCode;
25 private long responseTime = 0;
28 private @JsonProperty(
"created_at") String createdAt;
30 private @JsonProperty(
"done_reason") String doneReason;
31 private List<Integer> context;
32 private @JsonProperty(
"total_duration") Long totalDuration;
33 private @JsonProperty(
"load_duration") Long loadDuration;
34 private @JsonProperty(
"prompt_eval_count") Integer promptEvalCount;
35 private @JsonProperty(
"prompt_eval_duration") Long promptEvalDuration;
36 private @JsonProperty(
"eval_count") Integer evalCount;
37 private @JsonProperty(
"eval_duration") Long evalDuration;
40 this.response = response;
41 this.responseTime = responseTime;
42 this.httpStatusCode = httpStatusCode;
48 return getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(
this);
49 }
catch (JsonProcessingException e) {
50 throw new RuntimeException(e);
61 Map<String, Object> response = getObjectMapper().readValue(this.getResponse(),
62 new TypeReference<Map<String, Object>>() {
65 }
catch (JsonProcessingException e) {
66 throw new RuntimeException(e);
78 public <T> T getStructuredResponse(Class<T> clazz) {
80 return getObjectMapper().readValue(this.getResponse(), clazz);
81 }
catch (JsonProcessingException e) {
82 throw new RuntimeException(e);
Map< String, Object > getStructuredResponse()
OllamaStructuredResult(String response, long responseTime, int httpStatusCode)