Skip to content

使用XStream 报错:Error: The key-value separator ":" is not found in the sse line chunk! #447

Open
@EternallyTm

Description

重现步骤

const response = await fetch('/api/v1/chat/assistant/chat', {
method: 'POST',
body: JSON.stringify(chatParam),
headers: {
'Content-Type': 'application/json',
'Authorization': Bearer ${token},
'Accept': 'text/event-stream', // 告诉服务器返回流式事件
},
})
if (!response || !response.body) {
onError(new Error("请求发生异常"));
return;
}
if (!response.ok) {
onError(new Error(HTTP error! Status: ${response.status}));
}
for await (const chunk of XStream({
readableStream: response.body,
})) {
console.log(chunk);
}
使用如下代码处理接收后端流式输出,会报错:Error: The key-value separator ":" is not found in the sse line chunk!
后端请求结果如下:
data: {"message": "你好", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "!", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "作为", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "专业的", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "AI", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "助手", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": ",", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "我", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "随时", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "准备", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "回答", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "你的", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "问题", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "或", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "帮助你", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "解决问题", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "。", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "有什么", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "我可以", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "帮助", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "你的", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "吗", "id": "RTOy7TQVDAv3OIhp"}

data: {"message": "?", "id": "RTOy7TQVDAv3OIhp"}

当前行为

No response

预期行为

No response

上下文

No response

版本

1.0.4

您在哪些浏览器上遇到了这个问题?

No response

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions