Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public void onEvent(EventSource eventSource, String id, String type, String data
String text = chatCompletions.getChoices().get(0).getDelta()==null?
chatCompletions.getChoices().get(0).getText()
:chatCompletions.getChoices().get(0).getDelta().getContent();
// Local LLMs (e.g. llama.cpp) may return null content in the first SSE chunk
// (only role is present). Treat null as empty string to avoid NullPointerException.
if (text == null) {
text = "";
}
message.setContent(text);
sseEmitter.send(SseEmitter.event()
.id(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public void onEvent(EventSource eventSource, String id, String type, @NotNull St
String text = chatCompletions.getChoices().get(0).getDelta()==null?
chatCompletions.getChoices().get(0).getText()
:chatCompletions.getChoices().get(0).getDelta().getContent();
// The first SSE chunk may carry only "role" with null "content".
// Guard against NullPointerException from Message.setContent().
if (text == null) {
text = "";
}

Message message = new Message();
message.setContent(text);
Expand Down