赞
踩
async function getStream() { try { let response = await fetch('/chat/stream/你好?'); // /chat/stream/后面跟问题 if (!response.ok) { throw new Error('Network response was not ok'); } const reader = response.body.getReader(); const textDecoder = new TextDecoder(); let isEnd = false; params.text = '' while (!isEnd) { const { done, value } = await reader.read(); if (done) { isEnd = true break; } const chunkText = textDecoder.decode(value); console.log(chunkText,'qing') params.text += chunkText; } } catch (e) { console.log(e); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。