revert OllamaResult.java

Signed-off-by: Amith Koujalgi <koujalgi.amith@gmail.com>
This commit is contained in:
Amith Koujalgi 2025-03-24 18:24:09 +05:30
parent e7e71f6421
commit 1bda78e35b

View File

@ -1,25 +1,15 @@
package io.github.ollama4j.models.response; package io.github.ollama4j.models.response;
import static io.github.ollama4j.utils.Utils.getObjectMapper;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.Data; import lombok.Data;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
import static io.github.ollama4j.utils.Utils.getObjectMapper;
/** The type Ollama result. */ /** The type Ollama result. */
@Getter @Getter
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Data @Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class OllamaResult { public class OllamaResult {
/** /**
* -- GETTER -- * -- GETTER --
@ -27,7 +17,7 @@ public class OllamaResult {
* *
* @return String completion/response text * @return String completion/response text
*/ */
private String response; private final String response;
/** /**
* -- GETTER -- * -- GETTER --
@ -45,19 +35,6 @@ public class OllamaResult {
*/ */
private long responseTime = 0; private long responseTime = 0;
/**
* -- GETTER --
* Get the model name used for the response.
*
* @return String - model name
*/
private String model;
@JsonCreator
public OllamaResult(@JsonProperty("response") String response) {
this.response = response;
}
public OllamaResult(String response, long responseTime, int httpStatusCode) { public OllamaResult(String response, long responseTime, int httpStatusCode) {
this.response = response; this.response = response;
this.responseTime = responseTime; this.responseTime = responseTime;
@ -72,36 +49,4 @@ public class OllamaResult {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
/**
* Get the structured response if the response is a JSON object.
*
* @return Map - structured response
*/
public Map<String, Object> getStructuredResponse() {
try {
Map<String, Object> response = getObjectMapper().readValue(this.getResponse(),
new TypeReference<Map<String, Object>>() {
});
return response;
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
/**
* Get the structured response mapped to a specific class type.
*
* @param <T> The type of class to map the response to
* @param clazz The class to map the response to
* @return An instance of the specified class with the response data
* @throws RuntimeException if there is an error mapping the response
*/
public <T> T getStructuredResponse(Class<T> clazz) {
try {
return getObjectMapper().readValue(this.getResponse(), clazz);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
} }