images = new ArrayList<>();
for (File imageFile : imageFiles) {
images.add(encodeFileToBase64(imageFile));
@@ -545,10 +521,12 @@ public class OllamaAPI {
* Convenience method to call Ollama API without streaming responses.
*
* Uses {@link #generateWithImageFiles(String, String, List, Options, OllamaStreamHandler)}
+ *
+ * @throws OllamaBaseException if the response indicates an error status
+ * @throws IOException if an I/O error occurs during the HTTP request
+ * @throws InterruptedException if the operation is interrupted
*/
- public OllamaResult generateWithImageFiles(
- String model, String prompt, List imageFiles, Options options)
- throws OllamaBaseException, IOException, InterruptedException {
+ public OllamaResult generateWithImageFiles(String model, String prompt, List imageFiles, Options options) throws OllamaBaseException, IOException, InterruptedException {
return generateWithImageFiles(model, prompt, imageFiles, options, null);
}
@@ -564,10 +542,12 @@ public class OllamaAPI {
* details on the options
* @param streamHandler optional callback consumer that will be applied every time a streamed response is received. If not set, the stream parameter of the request is set to false.
* @return OllamaResult that includes response text and time taken for response
+ * @throws OllamaBaseException if the response indicates an error status
+ * @throws IOException if an I/O error occurs during the HTTP request
+ * @throws InterruptedException if the operation is interrupted
+ * @throws URISyntaxException if the URI for the request is malformed
*/
- public OllamaResult generateWithImageURLs(
- String model, String prompt, List imageURLs, Options options, OllamaStreamHandler streamHandler)
- throws OllamaBaseException, IOException, InterruptedException, URISyntaxException {
+ public OllamaResult generateWithImageURLs(String model, String prompt, List imageURLs, Options options, OllamaStreamHandler streamHandler) throws OllamaBaseException, IOException, InterruptedException, URISyntaxException {
List images = new ArrayList<>();
for (String imageURL : imageURLs) {
images.add(encodeByteArrayToBase64(Utils.loadImageBytesFromUrl(imageURL)));
@@ -581,10 +561,12 @@ public class OllamaAPI {
* Convenience method to call Ollama API without streaming responses.
*
* Uses {@link #generateWithImageURLs(String, String, List, Options, OllamaStreamHandler)}
+ * @throws OllamaBaseException if the response indicates an error status
+ * @throws IOException if an I/O error occurs during the HTTP request
+ * @throws InterruptedException if the operation is interrupted
+ * @throws URISyntaxException if the URI for the request is malformed
*/
- public OllamaResult generateWithImageURLs(String model, String prompt, List imageURLs,
- Options options)
- throws OllamaBaseException, IOException, InterruptedException, URISyntaxException {
+ public OllamaResult generateWithImageURLs(String model, String prompt, List imageURLs, Options options) throws OllamaBaseException, IOException, InterruptedException, URISyntaxException {
return generateWithImageURLs(model, prompt, imageURLs, options, null);
}
@@ -599,6 +581,9 @@ public class OllamaAPI {
* @throws OllamaBaseException any response code than 200 has been returned
* @throws IOException in case the responseStream can not be read
* @throws InterruptedException in case the server is not reachable or network issues happen
+ * @throws OllamaBaseException if the response indicates an error status
+ * @throws IOException if an I/O error occurs during the HTTP request
+ * @throws InterruptedException if the operation is interrupted
*/
public OllamaChatResult chat(String model, List messages) throws OllamaBaseException, IOException, InterruptedException {
OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(model);
@@ -615,6 +600,9 @@ public class OllamaAPI {
* @throws OllamaBaseException any response code than 200 has been returned
* @throws IOException in case the responseStream can not be read
* @throws InterruptedException in case the server is not reachable or network issues happen
+ * @throws OllamaBaseException if the response indicates an error status
+ * @throws IOException if an I/O error occurs during the HTTP request
+ * @throws InterruptedException if the operation is interrupted
*/
public OllamaChatResult chat(OllamaChatRequest request) throws OllamaBaseException, IOException, InterruptedException {
return chat(request, null);
@@ -631,6 +619,9 @@ public class OllamaAPI {
* @throws OllamaBaseException any response code than 200 has been returned
* @throws IOException in case the responseStream can not be read
* @throws InterruptedException in case the server is not reachable or network issues happen
+ * @throws OllamaBaseException if the response indicates an error status
+ * @throws IOException if an I/O error occurs during the HTTP request
+ * @throws InterruptedException if the operation is interrupted
*/
public OllamaChatResult chat(OllamaChatRequest request, OllamaStreamHandler streamHandler) throws OllamaBaseException, IOException, InterruptedException {
OllamaChatEndpointCaller requestCaller = new OllamaChatEndpointCaller(host, basicAuth, requestTimeoutSeconds, verbose);
@@ -658,11 +649,8 @@ public class OllamaAPI {
return Base64.getEncoder().encodeToString(bytes);
}
- private OllamaResult generateSyncForOllamaRequestModel(
- OllamaGenerateRequest ollamaRequestModel, OllamaStreamHandler streamHandler)
- throws OllamaBaseException, IOException, InterruptedException {
- OllamaGenerateEndpointCaller requestCaller =
- new OllamaGenerateEndpointCaller(host, basicAuth, requestTimeoutSeconds, verbose);
+ private OllamaResult generateSyncForOllamaRequestModel(OllamaGenerateRequest ollamaRequestModel, OllamaStreamHandler streamHandler) throws OllamaBaseException, IOException, InterruptedException {
+ OllamaGenerateEndpointCaller requestCaller = new OllamaGenerateEndpointCaller(host, basicAuth, requestTimeoutSeconds, verbose);
OllamaResult result;
if (streamHandler != null) {
ollamaRequestModel.setStream(true);
@@ -680,10 +668,7 @@ public class OllamaAPI {
* @return HttpRequest.Builder
*/
private HttpRequest.Builder getRequestBuilderDefault(URI uri) {
- HttpRequest.Builder requestBuilder =
- HttpRequest.newBuilder(uri)
- .header("Content-Type", "application/json")
- .timeout(Duration.ofSeconds(requestTimeoutSeconds));
+ HttpRequest.Builder requestBuilder = HttpRequest.newBuilder(uri).header("Content-Type", "application/json").timeout(Duration.ofSeconds(requestTimeoutSeconds));
if (isBasicAuthCredentialsSet()) {
requestBuilder.header("Authorization", getBasicAuthHeaderValue());
}