https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/extended/component-plus/uploader.html
const requestTask = Taro.request({
url: `${app.chatUrl}/conversation/talk`,
method: "POST",
enableChunked: true,
responseType: "text",
data: {
prompt: requestQuestion,
message_id: uuid(),
parent_message_id: uuid(),
stream: true,
user_id: user_id,
},
success: response => {
console.log(response)
}
});
console.log(``, requestTask);
requestTask.onChunkReceived(function (response) {
console.log(1)
const arrayBuffer = response.data;
const uint8Array = new Uint8Array(arrayBuffer);
let text = String.fromCharCode.apply(null, uint8Array);
console.log(`text`, text);
if (text.trim() === "data: [DONE]") {
setLoading(false);
return;
}
const datas = text.split("data:");
datas.shift();
for (let i = 0; i < datas.length; i++) {
const part = datas[i];
console.log(`part`, part);
const datatxt = part.trim();
if (datatxt === "[DONE]") {
setLoading(false);
return;
} else {
const data = JSON.parse(datatxt);
setAnswer(data.message.content.parts[0]);
}
}
});
s数据是正常返回的,但是不触发onChunkReceived
HTTP/1.1 200
transfer-encoding: chunked
transfer-encoding: chunked
date: Mon, 17 Jul 2023 10:08:20 GMT
for-weapp-devtools: {"transfer-encoding":["chunked","chunked"],"date":["Mon, 17 Jul 2023 10:08:20 GMT"]}
z这是返回头
哇哇哇哇,解决了没有呀 我也遇到了
请问解决了吗
请问解决了吗,我也遇到了这个问题