修复同时输出的bug,增加输出的速度

This commit is contained in:
2025-11-10 16:33:25 +08:00
parent 168160bb4a
commit fa2f283da4
2 changed files with 22 additions and 5 deletions

View File

@@ -1312,6 +1312,11 @@
}
chatInput.value = "";
if (controller) {
controller.abort();
controller = null;
}
if (!sendBtnImg.classList.contains('none')) {
sendBtnImg.classList.add('none');
stopBtn.classList.remove('none')
@@ -1362,7 +1367,14 @@
while (true) {
const { done, value } = await reader.read();
if (done) break;
console.log(done, value, 'done')
if (done) {
const sendBtnImg = document.querySelector('#sendBtn img');
const stopBtn = document.querySelector('#stopBtn');
sendBtnImg.classList.add('none');
stopBtn.classList.remove('none');
break;
};
buffer += decoder.decode(value, { stream: true });
let lines = buffer.split("\n");
@@ -1373,8 +1385,14 @@
if (!line.startsWith("data:")) continue;
const data = line.slice(5).trim();
if (data === "[DONE]") {
console.log("完成回答", data)
if (data == "[DONE]") {
console.log("完成回答")
// 更新聊天滚动条
const sendBtnImg = document.querySelector('#sendBtn img');
const stopBtn = document.querySelector('#stopBtn');
sendBtnImg.classList.remove('none');
stopBtn.classList.add('none');
setTimeout(scrollToBottom, 0); // chatMessages.scrollTop = chatMessages.scrollHeight;
return;
@@ -1391,7 +1409,7 @@
// }
if (obj.content && obj.type !== "title") {
for (const char of obj.content) {
await new Promise(r => setTimeout(r, 20)); // 控制字速
await new Promise(r => setTimeout(r, 5)); // 控制字速
aiMsg.content += char;
msgDiv.innerHTML = marked.parse(aiMsg.content);

View File

@@ -281,7 +281,6 @@
background-size: cover;
background-repeat: no-repeat;
padding: 10px 0 20px 0;
;
}
/* 先给表格四列添加细微分色(可按需移除) */
@@ -333,7 +332,7 @@
<div class="title">
<h2>购买服务</h2>
<span class="header-colorful-text"
style="background-image: url('https://jsmaibu.com/upload/images/2025/9/756389b8bc935a9d.jpg');">
style="background-image: url('https://www.satabot.com/upload/images/2025/11/6e57112777bc93be.jpg');">
灵活,有竞争力的定价和持续增值的服务
</span>
</div>