Updated askAsync API to use OutputStream.write instead of DataOutputStream.writeBytes

This commit is contained in:
Amith Koujalgi 2023-11-12 23:53:36 +05:30
parent 7c4b17454b
commit df9b9af063

View File

@ -17,7 +17,10 @@ import org.apache.hc.core5.http.io.entity.StringEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
@ -281,8 +284,8 @@ public class OllamaAPI {
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setRequestProperty("Content-Type", "application/json");
try (DataOutputStream wr = new DataOutputStream(con.getOutputStream())) {
wr.writeBytes(ollamaRequestModel.toString());
try (OutputStream out = con.getOutputStream()) {
out.write(ollamaRequestModel.toString().getBytes(StandardCharsets.UTF_8));
}
OllamaAsyncResultCallback ollamaAsyncResultCallback = new OllamaAsyncResultCallback(con);
ollamaAsyncResultCallback.start();