We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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"}
Bearer ${token}
HTTP error! Status: ${response.status}
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"}
No response
1.0.4
The text was updated successfully, but these errors were encountered:
看数据没什么问题,确认下 response 是否是以空行结尾,感觉问题容易出现在这里。
比如一个正常的 SSE 返回结尾应该是这样「line 63 为空行」:
Sorry, something went wrong.
No branches or pull requests
重现步骤
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
The text was updated successfully, but these errors were encountered: