修改ai输出按字输出的效果
This commit is contained in:
25
index.html
25
index.html
@@ -4,6 +4,9 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<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>
|
||||
<link rel="icon" href="./img/logo.png" type="image/x-icon">
|
||||
<!-- <script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script> -->
|
||||
@@ -16,6 +19,7 @@
|
||||
display: flex;
|
||||
background: #f0f6fb;
|
||||
color: #333;
|
||||
width: 100%;
|
||||
|
||||
}
|
||||
|
||||
@@ -165,11 +169,14 @@
|
||||
flex-direction: column;
|
||||
background: #f9fcff;
|
||||
justify-content: space-between;
|
||||
width: calc(100% - 240px)
|
||||
}
|
||||
|
||||
.chat-container .content {
|
||||
height: 70%;
|
||||
overflow-y: auto;
|
||||
scrollbar-width: none;
|
||||
/* overflow-y: auto; */
|
||||
}
|
||||
|
||||
.chat-header {
|
||||
@@ -529,7 +536,7 @@
|
||||
flex-direction: column;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 8px 0 60px rgba(0, 0, 0, 0.04);
|
||||
z-index: 10;
|
||||
z-index: 1000;
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
height: 100%;
|
||||
@@ -556,6 +563,7 @@
|
||||
|
||||
.chat-messages {
|
||||
padding-bottom: 125px;
|
||||
/* height: 200px */
|
||||
/* 留出输入框空间 */
|
||||
}
|
||||
|
||||
@@ -574,6 +582,11 @@
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.chat-container .content {
|
||||
overflow-y: auto;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
|
||||
/* 按钮样式 */
|
||||
.userinfo-toggle {
|
||||
padding: 7px 2px;
|
||||
@@ -999,10 +1012,11 @@
|
||||
q.addEventListener("click", () => {
|
||||
if (q.classList.contains("mainauestion")) {
|
||||
// q.style.display = 'none';
|
||||
if (!isMobile()) {
|
||||
document.querySelector('.fourquestionmain').style.display = 'none';
|
||||
document.querySelector('.sidequestion').style.display = 'flex';
|
||||
}
|
||||
// if (!isMobile()) {
|
||||
document.querySelector('.fourquestionmain').style.display = 'none';
|
||||
document.querySelector('.sidequestion').style.display = 'flex';
|
||||
document.querySelector('.chat-messages').style.height = '100%';
|
||||
// }
|
||||
|
||||
}
|
||||
isPre = true;
|
||||
@@ -1343,6 +1357,7 @@
|
||||
// }
|
||||
if (obj.content && obj.type !== "title") {
|
||||
for (const char of obj.content) {
|
||||
await new Promise(r => setTimeout(r, 20)); // 控制字速
|
||||
aiMsg.content += char;
|
||||
msgDiv.innerHTML = marked.parse(aiMsg.content);
|
||||
|
||||
|
||||
28
server2.js
28
server2.js
@@ -513,10 +513,16 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
||||
{
|
||||
const delta = chunk.choices[0]?.delta?.content || "";
|
||||
sceneText += delta;
|
||||
if (delta)
|
||||
res.write(
|
||||
`data: ${JSON.stringify({ type: "scene", content: delta })}\n\n`
|
||||
);
|
||||
// if (delta)
|
||||
// res.write(
|
||||
// `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("====== 图像分析结束 ======")
|
||||
|
||||
@@ -563,10 +569,16 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
||||
const delta = chunk.choices[0]?.delta?.content || "";
|
||||
llmText += delta;
|
||||
|
||||
if (delta)
|
||||
res.write(
|
||||
`data: ${JSON.stringify({ type: "llm", content: delta})}\n\n`
|
||||
);
|
||||
// if (delta)
|
||||
// res.write(
|
||||
// `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)); // 控制渲染节奏
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user