Dify Streaming Parsing Error
When using response_mode: 'streaming', we frequently encounter malformed JSON errors, especially with long responses or special characters that are not properly escaped. This leads to issues such as:
Fail: While creating Dify chat message: Unterminated string in JSON at position 9582 (line 1 column 9583)
Example
This happens because Dify sends each node's data (such as Workflow Started, Node Started, HTTP Request, etc.) as streaming chunks, which mimics a verbose debug log.
However, this data can be incomplete or improperly escaped, causing JSON parsing failures when trying to construct a final message.
I had previously sent a change: #2244
Your proposal was using: https://ai-sdk.dev/providers/community-providers/dify
Any specs I should follow?
Thanks, and sorry for closing the PR 🙏
It should be retro-compatible with the existing block settings.
Ideally, it should use runChatCompletionStream and runChatCompletion like other AI blocks.
Thank you for contributing!!
Thanks, and sorry for closing the PR 🙏
It should be retro-compatible with the existing block settings.
Ideally, it should use
runChatCompletionStreamandrunChatCompletionlike other AI blocks.Thank you for contributing!!
No worries! I should asked first.
I did like you asked using runChatCompletionStream and runChatCompletion.
If you can, the changes are on this repo/branch. Dify Implementation
I'm just testing to check if it's retro-compatible.
If you're happy with the start of the implementation, I'll open the PR and we can talk about the changes needed there.
Thanks!
Did few tests, the code is working with old blocks too.
Great! You can create a PR once you feel it's ready to review :)
Done! We shall left the issue open till the PR is finished, right?