69 ollamaRequestModel.setStream(
true);
70 HttpClient httpClient = HttpClient.newHttpClient();
72 long startTime = System.currentTimeMillis();
76 HttpRequest.BodyPublishers.ofString(
78 .header(
"Content-Type",
"application/json")
79 .timeout(Duration.ofSeconds(requestTimeoutSeconds))
81 HttpResponse<InputStream> response =
82 httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
83 int statusCode = response.statusCode();
84 this.httpStatusCode = statusCode;
86 InputStream responseBodyStream = response.body();
87 try (BufferedReader reader =
88 new BufferedReader(
new InputStreamReader(responseBodyStream, StandardCharsets.UTF_8))) {
90 StringBuilder responseBuffer =
new StringBuilder();
91 while ((line = reader.readLine()) !=
null) {
92 if (statusCode == 404) {
95 stream.add(ollamaResponseModel.getError());
96 responseBuffer.append(ollamaResponseModel.getError());
100 String res = ollamaResponseModel.getResponse();
102 if (!ollamaResponseModel.isDone()) {
103 responseBuffer.append(res);
108 this.succeeded =
true;
109 this.completeResponse = responseBuffer.toString();
110 long endTime = System.currentTimeMillis();
111 responseTime = endTime - startTime;
113 if (statusCode != 200) {
117 this.succeeded =
false;
118 this.completeResponse =
"[FAILED] " + e.getMessage();