// 在页面中创建 XMLHttpRequest 对象
let xhr = new plus.net.XMLHttpRequest()
//const msgNum = messageList.value.length;
xhr.onreadystatechange = function() {
console.log("onreadystatechange: " + xhr.readyState);
if (xhr.readyState == 3) {
> **// 这里安卓端只执行一次,ios端正常**
// 处理 HTTP 数据块
//let result=JSON.parse(xhr.responseText)
that.parseContent(xhr.responseText)
//console.log(xhr)
}
if (xhr.readyState == 4) {
console.log("问答完毕")
that.loadding = false
that.messageList.push({
content: that.messages[that.messages.length - 1].content,
role: "assistant"
})
uni.setStorageSync("chatgpt_messages", that.messages)
uni.setStorageSync("chatgpt_messageList", that.messageList)
}
}
xhr.onload = function() {
console.log("onreadystatechange: " + xhr.readyState);
}
xhr.open("POST", "https://111.com/completions", true)
xhr.setRequestHeader("Content-type", "application/json");
//xhr.responseType = "document"
//xhr.timeout = 0
xhr.send(JSON.stringify({
model: "gpt-3.5-turbo",
stream: true,
messages: messageList,
}))
howryanl (作者)
改成webview了
2024-01-10 13:33