前端html

文章

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);
}


Copyright © 2024  Erbing 版权所有  备案号:黑ICP备17006126号-3

0.982790s