var r = '' requestTask.onChunkReceived(chunk => { const arrayBuffer = chunk.data; const uint8Array = new Uint8Array(arrayBuffer); const str = new TextEncoding.TextDecoder('utf-8').decode(uint8Array); const data = str.split('data: ') data.forEach(el=>{ //排除空字符串和[DONE] if (el.startsWith('{')){ var json = JSON.parse(el) var text = json.choices[0].delta.content if (typeof text === 'string'){ r +=text this.setData({ typingText:r }) } } }) })
小程序请求的流式数据onChunkReceived返回的如何处理?[图片] [图片]
2023-07-22