mirror of
https://github.com/amithkoujalgi/ollama4j.git
synced 2025-05-15 03:47:13 +02:00
revert OllamaResult.java
Signed-off-by: Amith Koujalgi <koujalgi.amith@gmail.com>
This commit is contained in:
parent
e7e71f6421
commit
1bda78e35b
@ -1,37 +1,27 @@
|
|||||||
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 --
|
||||||
* Get the completion/response text
|
* Get the completion/response text
|
||||||
*
|
*
|
||||||
* @return String completion/response text
|
* @return String completion/response text
|
||||||
*/
|
*/
|
||||||
private String response;
|
private final String response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* -- GETTER --
|
* -- GETTER --
|
||||||
* Get the response status code.
|
* Get the response status code.
|
||||||
*
|
*
|
||||||
* @return int - response status code
|
* @return int - response status code
|
||||||
*/
|
*/
|
||||||
@ -39,25 +29,12 @@ public class OllamaResult {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* -- GETTER --
|
* -- GETTER --
|
||||||
* Get the response time in milliseconds.
|
* Get the response time in milliseconds.
|
||||||
*
|
*
|
||||||
* @return long - response time in milliseconds
|
* @return long - response time in milliseconds
|
||||||
*/
|
*/
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user