typebot.io icon indicating copy to clipboard operation
typebot.io copied to clipboard

Dify Streaming Parsing Error

Open CosmoAbdon opened this issue 9 months ago • 5 comments

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

Image

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?

CosmoAbdon avatar Jul 07 '25 10:07 CosmoAbdon

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!!

baptisteArno avatar Jul 07 '25 12:07 baptisteArno

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!!

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!

CosmoAbdon avatar Jul 07 '25 20:07 CosmoAbdon

Did few tests, the code is working with old blocks too.

CosmoAbdon avatar Jul 08 '25 01:07 CosmoAbdon

Great! You can create a PR once you feel it's ready to review :)

baptisteArno avatar Jul 09 '25 08:07 baptisteArno

Done! We shall left the issue open till the PR is finished, right?

CosmoAbdon avatar Jul 09 '25 09:07 CosmoAbdon