只是记录一下网上搜集的代码片段,貌似服务端并没有流式返回所以效果未知。
const response = await fetch(`/api/?s=Chat.Chat.Analysis&file_hash=${fileHash}`)
/* if (!response.body) return
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader()
while (true) {
let { value, done } = await reader.read()
if (done) break
value = value?.replace('undefined', '')
output.value += value?.replace('undefined', '')
console.log('收到', value)
} */
const reader = response.body?.getReader()
if (!reader) {
throw new Error('无法读取响应流')
}
isProcessing.value = false
result.value = ''
while (true) {
const {
done,
value,
} = await reader.read()
if (done) break
const v = new TextDecoder().decode(value)
result.value += v
console.log('收到', v)
}
Comments | NOTHING