文章
js接收流式响应
时间:2024-12-17 11:24
阅读:432
const response = await fetch('/chat',{
method: 'post',
headers: {
'Content-Type': 'application/json'
},
body:JSON.stringify({
'message':question
})
});
const reader = response.body.getReader();
var state = true;
while (state) {
const { done, value } = await reader.read();
if (done) {
break;
}
let res = new TextDecoder().decode(value);
}