9package io.github.ollama4j.models.response;
11import static io.github.ollama4j.utils.Utils.getObjectMapper;
13import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
14import com.fasterxml.jackson.annotation.JsonProperty;
15import com.fasterxml.jackson.core.JsonProcessingException;
16import com.fasterxml.jackson.core.type.TypeReference;
21import lombok.NoArgsConstructor;
24@SuppressWarnings(
"unused")
27@JsonIgnoreProperties(ignoreUnknown =
true)
29 private String response;
30 private String thinking;
31 private int httpStatusCode;
32 private long responseTime = 0;
35 private @JsonProperty(
"created_at") String createdAt;
37 private @JsonProperty(
"done_reason") String doneReason;
38 private List<Integer> context;
39 private @JsonProperty(
"total_duration") Long totalDuration;
40 private @JsonProperty(
"load_duration") Long loadDuration;
41 private @JsonProperty(
"prompt_eval_count") Integer promptEvalCount;
42 private @JsonProperty(
"prompt_eval_duration") Long promptEvalDuration;
43 private @JsonProperty(
"eval_count") Integer evalCount;
44 private @JsonProperty(
"eval_duration") Long evalDuration;
47 this.response = response;
48 this.responseTime = responseTime;
49 this.httpStatusCode = httpStatusCode;
55 return getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(
this);
56 }
catch (JsonProcessingException e) {
57 throw new RuntimeException(e);
68 return getObjectMapper()
69 .readValue(this.getResponse(),
new TypeReference<Map<String, Object>>() {});
70 }
catch (JsonProcessingException e) {
71 throw new RuntimeException(e);
83 public <T> T getStructuredResponse(Class<T> clazz) {
85 return getObjectMapper().readValue(this.getResponse(), clazz);
86 }
catch (JsonProcessingException e) {
87 throw new RuntimeException(e);
Map< String, Object > getStructuredResponse()
OllamaStructuredResult(String response, long responseTime, int httpStatusCode)