修改ai输出按字输出的效果

This commit is contained in:
2025-11-07 16:47:28 +08:00
parent fc279a1b05
commit e2f3f6c8d8
2 changed files with 40 additions and 13 deletions

View File

@@ -4,6 +4,9 @@
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="Thu, 01 Jan 1970 00:00:00 GMT">
<title>新能源智能体</title> <title>新能源智能体</title>
<link rel="icon" href="./img/logo.png" type="image/x-icon"> <link rel="icon" href="./img/logo.png" type="image/x-icon">
<!-- <script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script> --> <!-- <script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script> -->
@@ -16,6 +19,7 @@
display: flex; display: flex;
background: #f0f6fb; background: #f0f6fb;
color: #333; color: #333;
width: 100%;
} }
@@ -165,11 +169,14 @@
flex-direction: column; flex-direction: column;
background: #f9fcff; background: #f9fcff;
justify-content: space-between; justify-content: space-between;
width: calc(100% - 240px)
} }
.chat-container .content { .chat-container .content {
height: 70%; height: 70%;
overflow-y: auto; overflow-y: auto;
scrollbar-width: none;
/* overflow-y: auto; */
} }
.chat-header { .chat-header {
@@ -529,7 +536,7 @@
flex-direction: column; flex-direction: column;
transition: all 0.3s ease; transition: all 0.3s ease;
box-shadow: 8px 0 60px rgba(0, 0, 0, 0.04); box-shadow: 8px 0 60px rgba(0, 0, 0, 0.04);
z-index: 10; z-index: 1000;
position: absolute; position: absolute;
top: 10px; top: 10px;
height: 100%; height: 100%;
@@ -556,6 +563,7 @@
.chat-messages { .chat-messages {
padding-bottom: 125px; padding-bottom: 125px;
/* height: 200px */
/* 留出输入框空间 */ /* 留出输入框空间 */
} }
@@ -574,6 +582,11 @@
align-items: center; align-items: center;
} }
.chat-container .content {
overflow-y: auto;
scrollbar-width: none;
}
/* 按钮样式 */ /* 按钮样式 */
.userinfo-toggle { .userinfo-toggle {
padding: 7px 2px; padding: 7px 2px;
@@ -999,10 +1012,11 @@
q.addEventListener("click", () => { q.addEventListener("click", () => {
if (q.classList.contains("mainauestion")) { if (q.classList.contains("mainauestion")) {
// q.style.display = 'none'; // q.style.display = 'none';
if (!isMobile()) { // if (!isMobile()) {
document.querySelector('.fourquestionmain').style.display = 'none'; document.querySelector('.fourquestionmain').style.display = 'none';
document.querySelector('.sidequestion').style.display = 'flex'; document.querySelector('.sidequestion').style.display = 'flex';
} document.querySelector('.chat-messages').style.height = '100%';
// }
} }
isPre = true; isPre = true;
@@ -1343,6 +1357,7 @@
// } // }
if (obj.content && obj.type !== "title") { if (obj.content && obj.type !== "title") {
for (const char of obj.content) { for (const char of obj.content) {
await new Promise(r => setTimeout(r, 20)); // 控制字速
aiMsg.content += char; aiMsg.content += char;
msgDiv.innerHTML = marked.parse(aiMsg.content); msgDiv.innerHTML = marked.parse(aiMsg.content);

View File

@@ -513,10 +513,16 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
{ {
const delta = chunk.choices[0]?.delta?.content || ""; const delta = chunk.choices[0]?.delta?.content || "";
sceneText += delta; sceneText += delta;
if (delta) // if (delta)
res.write( // res.write(
`data: ${JSON.stringify({ type: "scene", content: delta })}\n\n` // `data: ${JSON.stringify({ type: "scene", content: delta })}\n\n`
); // );
if (delta) {
for (const ch of delta) {
res.write(`data: ${JSON.stringify({ type: "scene", content: ch })}\n\n`);
await new Promise(r => setTimeout(r, 0)); // 控制渲染节奏
}
}
} }
console.log("====== 图像分析结束 ======") console.log("====== 图像分析结束 ======")
@@ -563,10 +569,16 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
const delta = chunk.choices[0]?.delta?.content || ""; const delta = chunk.choices[0]?.delta?.content || "";
llmText += delta; llmText += delta;
if (delta) // if (delta)
res.write( // res.write(
`data: ${JSON.stringify({ type: "llm", content: delta})}\n\n` // `data: ${JSON.stringify({ type: "llm", content: delta})}\n\n`
); // );
if (delta) {
for (const ch of delta) {
res.write(`data: ${JSON.stringify({ type: "llm", content: ch })}\n\n`);
await new Promise(r => setTimeout(r, 0)); // 控制渲染节奏
}
}
} }