fix: handle null content in SSE stream chunks for REST and Zhipu AI#1816
Open
octo-patch wants to merge 1 commit intoCodePhiliaX:mainfrom
Open
fix: handle null content in SSE stream chunks for REST and Zhipu AI#1816octo-patch wants to merge 1 commit intoCodePhiliaX:mainfrom
octo-patch wants to merge 1 commit intoCodePhiliaX:mainfrom
Conversation
…isteners When local LLMs (e.g. llama.cpp) or Zhipu AI return SSE stream responses, the first chunk may contain only a "role" field with "content": null. This caused a NullPointerException in Message.setContent() due to @nonnull enforcement, making the entire AI chat session fail. Treat null content as an empty string (matching the behaviour of FastChatAIEventSourceListener) so the stream continues gracefully. Fixes CodePhiliaX#1808 Fixes CodePhiliaX#1788
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1808
Fixes #1788
Problem
When using local LLMs (e.g.
llama.cpp) with the custom REST AI endpoint, or when using Zhipu AI, the SSE stream's first chunk typically contains only therolefield with"content": null. The two affected listeners passed thisnullvalue directly toMessage.setContent(), which throws aNullPointerException(caused by a@NonNullenforcement in Lombok-generated code), making the entire AI chat session fail immediately.Affected files:
RestAIEventSourceListener.java— used by the custom REST AI integration (issue Bug: #1808)ZhipuChatAIEventSourceListener.java— used by the Zhipu AI integration (issue Bug: zhipu api response can't be recorgnized #1788)Solution
Added a null guard after extracting
textfrom the delta: iftextisnull, it is replaced with an empty string before callingmessage.setContent(text). This matches the existing behaviour ofFastChatAIEventSourceListener, which already handles this case correctly.Testing
FastChatAIEventSourceListener.