api 流式 sse调用后 返回的数据 解析失败 #344

Closed
opened 2026-02-21 17:26:52 -05:00 by yindo · 2 comments
Owner

Originally created by @zhenjiaWang on GitHub (Aug 4, 2023).

Originally assigned to: @iamjoel, @crazywoola on GitHub.

请求后 在返回的监听过程中
answer 返回了的时候有时候是Unicode 有时候并不是。ai回答过程中通常会包含\n \r类似字符

在转义过程中不稳定

data: {"event": "message", "task_id": "2c12b654-46f9-40c7-bc4b-7a93481436d9", "id": "17a50f89-0cd0-41e5-b70d-12c703db4a7c", "answer": ""\n", "created_at": 1691179729, "conversation_id": "e54e07a0-40ee-4526-8838-205524fa8347"}

以上是我得到的返回

这个string 在JSON.parse时候会报错 因为 "answer": ""\n"

Originally created by @zhenjiaWang on GitHub (Aug 4, 2023). Originally assigned to: @iamjoel, @crazywoola on GitHub. 请求后 在返回的监听过程中 answer 返回了的时候有时候是Unicode 有时候并不是。ai回答过程中通常会包含\n \r类似字符 在转义过程中不稳定 data: {"event": "message", "task_id": "2c12b654-46f9-40c7-bc4b-7a93481436d9", "id": "17a50f89-0cd0-41e5-b70d-12c703db4a7c", "answer": "\"\n", "created_at": 1691179729, "conversation_id": "e54e07a0-40ee-4526-8838-205524fa8347"} 以上是我得到的返回 这个string 在JSON.parse时候会报错 因为 "answer": "\"\n"
yindo closed this issue 2026-02-21 17:26:52 -05:00
Author
Owner

@crazywoola commented on GitHub (Aug 4, 2023):

https://github.com/langgenius/dify/blob/main/web/service/base.ts
Try to use the same approach here

@crazywoola commented on GitHub (Aug 4, 2023): https://github.com/langgenius/dify/blob/main/web/service/base.ts Try to use the same approach here
Author
Owner

@zhenjiaWang commented on GitHub (Aug 5, 2023):

https://github.com/langgenius/dify/blob/main/web/service/base.ts

谢谢解决了。

@zhenjiaWang commented on GitHub (Aug 5, 2023): > https://github.com/langgenius/dify/blob/main/web/service/base.ts 谢谢解决了。
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#344