diff --git a/service/src/main/java/com/theokanning/openai/service/ResponseBodyCallback.java b/service/src/main/java/com/theokanning/openai/service/ResponseBodyCallback.java index 3f0dbf1c..9a4c7939 100644 --- a/service/src/main/java/com/theokanning/openai/service/ResponseBodyCallback.java +++ b/service/src/main/java/com/theokanning/openai/service/ResponseBodyCallback.java @@ -58,7 +58,7 @@ public void onResponse(Call call, Response response) String line; SSE sse = null; - while ((line = reader.readLine()) != null) { + while (!emitter.isCancelled() && (line = reader.readLine()) != null) { if (line.startsWith("data:")) { String data = line.substring(5).trim(); sse = new SSE(data); @@ -86,7 +86,7 @@ public void onResponse(Call call, Response response) try { reader.close(); } catch (IOException e) { - // do nothing + // do nothing } } } @@ -96,4 +96,4 @@ public void onResponse(Call call, Response response) public void onFailure(Call call, Throwable t) { emitter.onError(t); } -} \ No newline at end of file +}