深度思考finish
This commit is contained in:
177
index.html
177
index.html
@@ -1046,6 +1046,11 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
}
|
}
|
||||||
|
.no-after::after {
|
||||||
|
content: none !important;
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.popbgc {
|
.popbgc {
|
||||||
background-color: rgba(0, 0, 0, 0.4);
|
background-color: rgba(0, 0, 0, 0.4);
|
||||||
@@ -1189,7 +1194,7 @@
|
|||||||
|
|
||||||
.thinking-loading::after {
|
.thinking-loading::after {
|
||||||
content: '';
|
content: '';
|
||||||
animation: dots 1.5s infinite;
|
animation: dots 0.8s infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes dots {
|
@keyframes dots {
|
||||||
@@ -1701,14 +1706,14 @@
|
|||||||
document.querySelectorAll('.logout1').forEach(el => {
|
document.querySelectorAll('.logout1').forEach(el => {
|
||||||
el.style.display = 'none';
|
el.style.display = 'none';
|
||||||
});
|
});
|
||||||
console.log(3)
|
|
||||||
document.querySelectorAll('.username').forEach((e) => {
|
document.querySelectorAll('.username').forEach((e) => {
|
||||||
e.textContent = params.get("nickname") || getcookie("nickname");
|
e.textContent = params.get("nickname") || getcookie("nickname");
|
||||||
})
|
})
|
||||||
|
|
||||||
document.querySelector(".userinfo-wrapper img").src = getcookie("headimgurl") || params.get("headingimg");
|
document.querySelector(".userinfo-wrapper img").src = getcookie("headimgurl") || params.get("headingimg");
|
||||||
userId = decodeURIComponent(Number(escape(atob(encodedUserId))));
|
userId = decodeURIComponent(Number(escape(atob(encodedUserId))));
|
||||||
console.log(4)
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
userId = decodeURIComponent(Number(escape(atob(encodedUserId))));
|
userId = decodeURIComponent(Number(escape(atob(encodedUserId))));
|
||||||
@@ -1929,7 +1934,7 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
isPre = true;//s是否预设题目
|
isPre = true;//s是否预设题目
|
||||||
console.log(isUpload, 88)
|
|
||||||
if (!sendParam.imageBase64 && !fileInput.files.length) {
|
if (!sendParam.imageBase64 && !fileInput.files.length) {
|
||||||
// if (!isUpload[activeChatId]) {
|
// if (!isUpload[activeChatId]) {
|
||||||
if (!hasImage) {
|
if (!hasImage) {
|
||||||
@@ -2081,7 +2086,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('click', (e) => {
|
document.addEventListener('click', (e) => {
|
||||||
console.log(toggleButton.contains(e.target), panel.contains(e.target))
|
|
||||||
if (!toggleButton.contains(e.target) && !panel.contains(e.target)) {
|
if (!toggleButton.contains(e.target) && !panel.contains(e.target)) {
|
||||||
panel.classList.remove('show');
|
panel.classList.remove('show');
|
||||||
}
|
}
|
||||||
@@ -2119,7 +2124,7 @@
|
|||||||
sendParam.sessionId = activeChatId;
|
sendParam.sessionId = activeChatId;
|
||||||
getHistory();
|
getHistory();
|
||||||
sessIdList.forEach((item, index) => {
|
sessIdList.forEach((item, index) => {
|
||||||
console.log(item, activeChatId);
|
|
||||||
|
|
||||||
const item1 = document.createElement("div");
|
const item1 = document.createElement("div");
|
||||||
item1.setAttribute("data-sessionid", item.sessId);
|
item1.setAttribute("data-sessionid", item.sessId);
|
||||||
@@ -2160,7 +2165,8 @@
|
|||||||
if (msg.image_base64) {
|
if (msg.image_base64) {
|
||||||
hasImage = true; // 只要有一个不为空,就置为 true
|
hasImage = true; // 只要有一个不为空,就置为 true
|
||||||
}
|
}
|
||||||
addMessage(msg.content, msg.role, msg.image_base64,msg.thinking);
|
|
||||||
|
addMessage(msg.content, msg.role, msg.image_base64,'',msg.thinking);
|
||||||
});
|
});
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
}
|
}
|
||||||
@@ -2185,7 +2191,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 内容 角色 图片 创造时间
|
// 内容 角色 图片 创造时间
|
||||||
function addMessage(content = '', role = "assistant", imgUrl = null, time = null,thinking='') {
|
function addMessage(content = '', role = "assistant", imgUrl = null, time = null,thinking) {
|
||||||
|
|
||||||
const msg = document.createElement("div");
|
const msg = document.createElement("div");
|
||||||
msg.className = `message ${role}`;
|
msg.className = `message ${role}`;
|
||||||
|
|
||||||
@@ -2205,8 +2212,8 @@
|
|||||||
// 思考过程(历史:已完成)
|
// 思考过程(历史:已完成)
|
||||||
// =========================
|
// =========================
|
||||||
let thinkingContentDiv = null;
|
let thinkingContentDiv = null;
|
||||||
|
if (thinking) {
|
||||||
|
|
||||||
if (role === "assistant" && thinking) {
|
|
||||||
const thinkingBox = document.createElement("div");
|
const thinkingBox = document.createElement("div");
|
||||||
thinkingBox.className = "thinking-box";
|
thinkingBox.className = "thinking-box";
|
||||||
|
|
||||||
@@ -2232,7 +2239,7 @@
|
|||||||
header.onclick = () => {
|
header.onclick = () => {
|
||||||
thinkingContentDiv.classList.toggle("collapsed");
|
thinkingContentDiv.classList.toggle("collapsed");
|
||||||
toggle.textContent =
|
toggle.textContent =
|
||||||
thinkingContentDiv.classList.contains("collapsed") ? "▶" : "⌄";
|
thinkingContentDiv.classList.contains("collapsed") ? "▶" : "";
|
||||||
};
|
};
|
||||||
|
|
||||||
header.appendChild(title);
|
header.appendChild(title);
|
||||||
@@ -2276,7 +2283,9 @@
|
|||||||
shareSpan.style.opacity = "0.75";
|
shareSpan.style.opacity = "0.75";
|
||||||
shareSpan.title = "分享";
|
shareSpan.title = "分享";
|
||||||
|
|
||||||
shareSpan.innerHTML = `<!-- 你的分享 SVG 原样放这里 -->`;
|
shareSpan.innerHTML = `
|
||||||
|
<svg t="1764059839985" class="icon" viewBox="0 0 1236 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5667" width="20" height="20"><path d="M741.743 1018.343c-28.287 0-50.917-11.315-73.547-28.288-22.63-22.63-39.602-50.917-39.602-84.862V792.044c-124.464 0-328.133 33.945-435.624 181.039-16.973 28.287-56.575 45.26-90.52 50.917H85.478C28.903 1012.685-5.042 961.768 0.616 905.193c28.287-243.27 113.15-418.652 260.243-537.458 107.492-84.862 231.956-130.122 367.735-141.437V118.807c0-50.917 22.63-96.177 67.89-113.15C736.086-5.657 781.345 0 815.29 33.945l362.077 367.735c28.288 22.63 45.26 56.574 50.918 96.176 5.657 39.603-5.658 79.205-33.945 107.492-5.658 5.658-11.315 16.972-22.63 22.63l-350.762 356.42c-22.63 22.63-50.918 33.945-79.205 33.945z m-90.52-339.448h90.52v226.298l356.42-367.734 5.658-5.658c5.657-5.657 5.657-16.972 5.657-22.63 0-11.315-5.657-16.972-11.315-22.63l-5.657-5.657-356.42-362.077V333.79l-79.205 5.658c-118.806 0-231.956 39.602-328.132 113.149-113.15 90.519-186.696 237.613-209.326 429.967 141.436-175.382 390.364-203.669 531.8-203.669z" p-id="5668" fill="#878895"></path></svg>
|
||||||
|
`;
|
||||||
shareSpan.onclick = () => {
|
shareSpan.onclick = () => {
|
||||||
generatePoster(content, imgUrl);
|
generatePoster(content, imgUrl);
|
||||||
};
|
};
|
||||||
@@ -2289,7 +2298,9 @@
|
|||||||
copySpan.style.opacity = "0.75";
|
copySpan.style.opacity = "0.75";
|
||||||
copySpan.title = "复制内容";
|
copySpan.title = "复制内容";
|
||||||
|
|
||||||
copySpan.innerHTML = `<!-- 你的复制 SVG 原样放这里 -->`;
|
copySpan.innerHTML = `
|
||||||
|
<svg t="1764549398754" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5335" width="20" height="20"><path d="M639.9 256.3H192.4c-35.2 0-63.9 28.8-63.9 63.9v575.4c0 35.2 28.8 63.9 63.9 63.9h447.5c35.2 0 63.9-28.8 63.9-63.9V320.2c0-35.1-28.8-63.9-63.9-63.9z m0 639.3H192.4V320.2h447.5v575.4z" fill="#878895" p-id="5336"></path><path d="M831.6 64.5H384.1c-35.2 0-63.9 28.8-63.9 63.9v63.9h63.9v-63.9h447.5v575.4h-63.9v63.9h63.9c35.2 0 63.9-28.8 63.9-63.9V128.4c0.1-35.1-28.7-63.9-63.9-63.9z" fill="#878895" p-id="5337"></path></svg>
|
||||||
|
`;
|
||||||
copySpan.onclick = async () => {
|
copySpan.onclick = async () => {
|
||||||
await navigator.clipboard.writeText(content);
|
await navigator.clipboard.writeText(content);
|
||||||
showToast("复制成功");
|
showToast("复制成功");
|
||||||
@@ -2372,7 +2383,7 @@
|
|||||||
|
|
||||||
|
|
||||||
function sendMessage(isPre) {
|
function sendMessage(isPre) {
|
||||||
console.log("发送消息1122");
|
|
||||||
if (controller) {
|
if (controller) {
|
||||||
showToast("请先停止对话");
|
showToast("请先停止对话");
|
||||||
return;
|
return;
|
||||||
@@ -2504,7 +2515,7 @@ const getAiResponse = async (img) => {
|
|||||||
|
|
||||||
thinkingToggleSpan = document.createElement("span");
|
thinkingToggleSpan = document.createElement("span");
|
||||||
thinkingToggleSpan.className = "thinking-toggle";
|
thinkingToggleSpan.className = "thinking-toggle";
|
||||||
thinkingToggleSpan.textContent = "⌄";
|
thinkingToggleSpan.textContent = "";
|
||||||
|
|
||||||
thinkingContentDiv = document.createElement("div");
|
thinkingContentDiv = document.createElement("div");
|
||||||
thinkingContentDiv.className = "thinking-content";
|
thinkingContentDiv.className = "thinking-content";
|
||||||
@@ -2582,11 +2593,111 @@ const getAiResponse = async (img) => {
|
|||||||
if (!line.startsWith("data:")) continue;
|
if (!line.startsWith("data:")) continue;
|
||||||
|
|
||||||
const data = line.slice(5).trim();
|
const data = line.slice(5).trim();
|
||||||
if (data === "[DONE]") {
|
if (data == "[DONE]") {
|
||||||
scrollToBottom();
|
console.log("完成回答");
|
||||||
controller = null;
|
controller = null;
|
||||||
return;
|
// 更新聊天滚动条
|
||||||
}
|
|
||||||
|
sendBtnImg.classList.remove('none');
|
||||||
|
stopBtn.forEach(e => {
|
||||||
|
e.classList.add('none')
|
||||||
|
|
||||||
|
})
|
||||||
|
// renderChatList();
|
||||||
|
// msgDiv.innerHTML = marked.parse(aiMsg.content);
|
||||||
|
// const shareSpan = document.createElement("span");
|
||||||
|
// shareSpan.style.display = "inline-flex";
|
||||||
|
// shareSpan.style.alignItems = "center";
|
||||||
|
// shareSpan.style.cursor = "pointer";
|
||||||
|
// shareSpan.style.marginTop = "8px";
|
||||||
|
// shareSpan.style.opacity = "0.75";
|
||||||
|
// shareSpan.style.transition = "opacity .2s";
|
||||||
|
// shareSpan.title = "分享";
|
||||||
|
|
||||||
|
// shareSpan.onmouseenter = () => shareSpan.style.opacity = "1";
|
||||||
|
// shareSpan.onmouseleave = () => shareSpan.style.opacity = "0.75";
|
||||||
|
|
||||||
|
// shareSpan.innerHTML = `
|
||||||
|
// <svg t="1764059839985" class="icon" viewBox="0 0 1236 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5667" width="20" height="20"><path d="M741.743 1018.343c-28.287 0-50.917-11.315-73.547-28.288-22.63-22.63-39.602-50.917-39.602-84.862V792.044c-124.464 0-328.133 33.945-435.624 181.039-16.973 28.287-56.575 45.26-90.52 50.917H85.478C28.903 1012.685-5.042 961.768 0.616 905.193c28.287-243.27 113.15-418.652 260.243-537.458 107.492-84.862 231.956-130.122 367.735-141.437V118.807c0-50.917 22.63-96.177 67.89-113.15C736.086-5.657 781.345 0 815.29 33.945l362.077 367.735c28.288 22.63 45.26 56.574 50.918 96.176 5.657 39.603-5.658 79.205-33.945 107.492-5.658 5.658-11.315 16.972-22.63 22.63l-350.762 356.42c-22.63 22.63-50.918 33.945-79.205 33.945z m-90.52-339.448h90.52v226.298l356.42-367.734 5.658-5.658c5.657-5.657 5.657-16.972 5.657-22.63 0-11.315-5.657-16.972-11.315-22.63l-5.657-5.657-356.42-362.077V333.79l-79.205 5.658c-118.806 0-231.956 39.602-328.132 113.149-113.15 90.519-186.696 237.613-209.326 429.967 141.436-175.382 390.364-203.669 531.8-203.669z" p-id="5668"></path></svg>
|
||||||
|
// `;
|
||||||
|
|
||||||
|
// shareSpan.onclick = () => {
|
||||||
|
// generatePoster(aiMsg.content);
|
||||||
|
// };
|
||||||
|
|
||||||
|
// if (role === "assistant") {
|
||||||
|
// 分享按钮
|
||||||
|
const shareSpan = document.createElement("span");
|
||||||
|
shareSpan.style.display = "inline-flex";
|
||||||
|
shareSpan.style.alignItems = "center";
|
||||||
|
shareSpan.style.cursor = "pointer";
|
||||||
|
shareSpan.style.marginTop = "8px";
|
||||||
|
shareSpan.style.opacity = "0.75";
|
||||||
|
shareSpan.style.transition = "opacity .2s";
|
||||||
|
shareSpan.title = "分享";
|
||||||
|
|
||||||
|
shareSpan.onmouseenter = () => shareSpan.style.opacity = "1";
|
||||||
|
shareSpan.onmouseleave = () => shareSpan.style.opacity = "0.75";
|
||||||
|
|
||||||
|
shareSpan.innerHTML = `
|
||||||
|
<svg t="1764059839985" class="icon" viewBox="0 0 1236 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5667" width="20" height="20"><path d="M741.743 1018.343c-28.287 0-50.917-11.315-73.547-28.288-22.63-22.63-39.602-50.917-39.602-84.862V792.044c-124.464 0-328.133 33.945-435.624 181.039-16.973 28.287-56.575 45.26-90.52 50.917H85.478C28.903 1012.685-5.042 961.768 0.616 905.193c28.287-243.27 113.15-418.652 260.243-537.458 107.492-84.862 231.956-130.122 367.735-141.437V118.807c0-50.917 22.63-96.177 67.89-113.15C736.086-5.657 781.345 0 815.29 33.945l362.077 367.735c28.288 22.63 45.26 56.574 50.918 96.176 5.657 39.603-5.658 79.205-33.945 107.492-5.658 5.658-11.315 16.972-22.63 22.63l-350.762 356.42c-22.63 22.63-50.918 33.945-79.205 33.945z m-90.52-339.448h90.52v226.298l356.42-367.734 5.658-5.658c5.657-5.657 5.657-16.972 5.657-22.63 0-11.315-5.657-16.972-11.315-22.63l-5.657-5.657-356.42-362.077V333.79l-79.205 5.658c-118.806 0-231.956 39.602-328.132 113.149-113.15 90.519-186.696 237.613-209.326 429.967 141.436-175.382 390.364-203.669 531.8-203.669z" p-id="5668" fill="#878895"></path></svg>
|
||||||
|
`;
|
||||||
|
|
||||||
|
|
||||||
|
shareSpan.onclick = () => {
|
||||||
|
generatePoster(answerContentDiv.innerHTML, img);
|
||||||
|
};
|
||||||
|
|
||||||
|
// msg.appendChild(shareSpan);
|
||||||
|
|
||||||
|
// ======================
|
||||||
|
// ✅ 复制按钮(新增)
|
||||||
|
// ======================
|
||||||
|
const copySpan = document.createElement("span");
|
||||||
|
copySpan.style.display = "inline-flex";
|
||||||
|
copySpan.style.alignItems = "center";
|
||||||
|
copySpan.style.cursor = "pointer";
|
||||||
|
copySpan.style.marginTop = "8px";
|
||||||
|
copySpan.style.marginLeft = "10px";
|
||||||
|
copySpan.style.opacity = "0.75";
|
||||||
|
copySpan.style.transition = "opacity .2s";
|
||||||
|
copySpan.title = "复制内容";
|
||||||
|
|
||||||
|
copySpan.onmouseenter = () => copySpan.style.opacity = "1";
|
||||||
|
copySpan.onmouseleave = () => copySpan.style.opacity = "0.75";
|
||||||
|
|
||||||
|
copySpan.innerHTML = `
|
||||||
|
<svg t="1764549398754" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5335" width="20" height="20"><path d="M639.9 256.3H192.4c-35.2 0-63.9 28.8-63.9 63.9v575.4c0 35.2 28.8 63.9 63.9 63.9h447.5c35.2 0 63.9-28.8 63.9-63.9V320.2c0-35.1-28.8-63.9-63.9-63.9z m0 639.3H192.4V320.2h447.5v575.4z" fill="#878895" p-id="5336"></path><path d="M831.6 64.5H384.1c-35.2 0-63.9 28.8-63.9 63.9v63.9h63.9v-63.9h447.5v575.4h-63.9v63.9h63.9c35.2 0 63.9-28.8 63.9-63.9V128.4c0.1-35.1-28.7-63.9-63.9-63.9z" fill="#878895" p-id="5337"></path></svg>
|
||||||
|
`;
|
||||||
|
|
||||||
|
copySpan.onclick = async () => {
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(answerBuffer);
|
||||||
|
copySpan.style.opacity = "1";
|
||||||
|
showToast("复制成功")
|
||||||
|
copySpan.title = "复制成功";
|
||||||
|
setTimeout(() => { copySpan.title = "复制内容"; }, 1200);
|
||||||
|
} catch (err) {
|
||||||
|
alert("复制失败,可能不支持 HTTPS 环境以外复制。");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
msgDiv.appendChild(shareSpan);
|
||||||
|
msgDiv.appendChild(copySpan);
|
||||||
|
}, 1000)
|
||||||
|
|
||||||
|
|
||||||
|
console.log("shareSpan appended?", msgDiv.contains(shareSpan));
|
||||||
|
|
||||||
|
|
||||||
|
scrollToBottom();
|
||||||
|
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let obj;
|
let obj;
|
||||||
try {
|
try {
|
||||||
@@ -2886,12 +2997,12 @@ const getAiResponse = async (img) => {
|
|||||||
function uploadFile(file) {
|
function uploadFile(file) {
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
console.log("上传文件:", file.name, URL.createObjectURL(file));
|
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
|
|
||||||
reader.onload = async function () {
|
reader.onload = async function () {
|
||||||
console.log(reader.result)
|
|
||||||
sendParam.imageBase64 = reader.result;
|
sendParam.imageBase64 = reader.result;
|
||||||
document.querySelectorAll(".img-row").forEach(e => {
|
document.querySelectorAll(".img-row").forEach(e => {
|
||||||
e.classList.remove("none");
|
e.classList.remove("none");
|
||||||
@@ -3073,7 +3184,7 @@ const getAiResponse = async (img) => {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
function getSessionList() {
|
function getSessionList() {
|
||||||
console.log(userId, "huoqu");
|
|
||||||
|
|
||||||
sendParam.userId = userId;
|
sendParam.userId = userId;
|
||||||
fetch(`https://serviceai.satabot.com/sessions?userId=${sendParam.userId}`, {
|
fetch(`https://serviceai.satabot.com/sessions?userId=${sendParam.userId}`, {
|
||||||
@@ -3128,8 +3239,10 @@ const getAiResponse = async (img) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
document.getElementById("stopBtn").addEventListener("click", () => {
|
document.getElementById("stopBtn").addEventListener("click", () => {
|
||||||
|
document.querySelectorAll('.thinking-loading').forEach(el=>el.classList.add('no-after'));
|
||||||
console.log(controller, '暂停消息');
|
console.log(controller, '暂停消息');
|
||||||
|
debugger;
|
||||||
|
|
||||||
isStopped = true;
|
isStopped = true;
|
||||||
|
|
||||||
if (reader) {
|
if (reader) {
|
||||||
@@ -3142,6 +3255,7 @@ const getAiResponse = async (img) => {
|
|||||||
controller = null;
|
controller = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (sendBtnImg.classList.contains('none')) {
|
if (sendBtnImg.classList.contains('none')) {
|
||||||
sendBtnImg.classList.remove('none');
|
sendBtnImg.classList.remove('none');
|
||||||
stopBtn.forEach(e => {
|
stopBtn.forEach(e => {
|
||||||
@@ -3149,8 +3263,17 @@ const getAiResponse = async (img) => {
|
|||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fetch("https://serviceai.satabot.com/stop", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify(sendParam),
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
document.getElementById("stopBtn1").addEventListener("click", () => {
|
document.getElementById("stopBtn1").addEventListener("click", () => {
|
||||||
|
document.querySelectorAll('.thinking-loading').forEach(el=>el.classList.add('no-after'));
|
||||||
|
|
||||||
console.log(controller, '暂停消息');
|
console.log(controller, '暂停消息');
|
||||||
isStopped = true;
|
isStopped = true;
|
||||||
@@ -3172,6 +3295,12 @@ const getAiResponse = async (img) => {
|
|||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
fetch("https://serviceai.satabot.com/stop", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify(sendParam),
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
// DOM 加载完成后执行
|
// DOM 加载完成后执行
|
||||||
console.log('DOM Ready');
|
console.log('DOM Ready');
|
||||||
@@ -3238,7 +3367,7 @@ const getAiResponse = async (img) => {
|
|||||||
showToast("请选择场景");
|
showToast("请选择场景");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(data, "收集信息")
|
|
||||||
|
|
||||||
// 发送POST请求到后端
|
// 发送POST请求到后端
|
||||||
const res = await fetch('https://serviceai.satabot.com/submit', {
|
const res = await fetch('https://serviceai.satabot.com/submit', {
|
||||||
|
|||||||
26
server2.js
26
server2.js
@@ -892,7 +892,7 @@ app.get("/history", async (req, res) => {
|
|||||||
|
|
||||||
// 查询数据库
|
// 查询数据库
|
||||||
const [rows] = await pool.query(
|
const [rows] = await pool.query(
|
||||||
"SELECT user_id, role, content, image_base64, created_at,title FROM ai_chat_messages WHERE session_id = ? ORDER BY id ASC",
|
"SELECT user_id, role, content, image_base64, created_at,title,thinking FROM ai_chat_messages WHERE session_id = ? ORDER BY id ASC",
|
||||||
[sessionId]
|
[sessionId]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1392,6 +1392,8 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("====== 开始图像分析11... ======");
|
||||||
|
|
||||||
const { requestId } = req.body;
|
const { requestId } = req.body;
|
||||||
|
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
@@ -1401,6 +1403,7 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
|||||||
"X-Accel-Buffering": "no",
|
"X-Accel-Buffering": "no",
|
||||||
});
|
});
|
||||||
res.flushHeaders?.();
|
res.flushHeaders?.();
|
||||||
|
res.socket.setNoDelay(true); // 禁用缓冲,实时推送
|
||||||
let aborted = false;
|
let aborted = false;
|
||||||
req.on("close", () => {
|
req.on("close", () => {
|
||||||
console.log("🔴 前端断开连接,停止整个分析流程");
|
console.log("🔴 前端断开连接,停止整个分析流程");
|
||||||
@@ -1443,6 +1446,8 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
|||||||
[sessId, userId || null]
|
[sessId, userId || null]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
console.log("====== 开始图像分析22... ======");
|
||||||
|
|
||||||
// 构建历史消息数组
|
// 构建历史消息数组
|
||||||
const historyMessages = historyRows.slice(-MAX_HISTORY).map(row => {
|
const historyMessages = historyRows.slice(-MAX_HISTORY).map(row => {
|
||||||
const message = {
|
const message = {
|
||||||
@@ -1470,6 +1475,8 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
|||||||
return message;
|
return message;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log("====== 开始图像分析33... ======");
|
||||||
|
|
||||||
// ------------------ 保存用户提问 ------------------
|
// ------------------ 保存用户提问 ------------------
|
||||||
await pool.query(
|
await pool.query(
|
||||||
"INSERT INTO ai_chat_messages (session_id, user_id, role, content, image_base64) VALUES (?, ?, 'user', ?, ?)",
|
"INSERT INTO ai_chat_messages (session_id, user_id, role, content, image_base64) VALUES (?, ?, 'user', ?, ?)",
|
||||||
@@ -1479,6 +1486,8 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
|||||||
// ------------------ 图像分析 ------------------
|
// ------------------ 图像分析 ------------------
|
||||||
let sceneText = "";
|
let sceneText = "";
|
||||||
|
|
||||||
|
console.log("====== 开始图像分析55... ======");
|
||||||
|
|
||||||
// If an image is uploaded, start with image analysis
|
// If an image is uploaded, start with image analysis
|
||||||
if (imageBase64) {
|
if (imageBase64) {
|
||||||
const imageAnalysisMessages = [
|
const imageAnalysisMessages = [
|
||||||
@@ -1531,8 +1540,10 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
console.log("====== 开始图像分析666... ======");
|
||||||
|
|
||||||
const completion = await client.chat.completions.create({
|
const completion = await client.chat.completions.create({
|
||||||
model: "gpt-4.1-mini",
|
model: "gpt-4.1",
|
||||||
stream: true,
|
stream: true,
|
||||||
messages: imageAnalysisMessages
|
messages: imageAnalysisMessages
|
||||||
});
|
});
|
||||||
@@ -1687,10 +1698,12 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
|||||||
console.log("====== 最终分析结束 ======");
|
console.log("====== 最终分析结束 ======");
|
||||||
|
|
||||||
// ------------------ Save Results to Database ------------------
|
// ------------------ Save Results to Database ------------------
|
||||||
|
|
||||||
|
sceneText += thinkingText;
|
||||||
if (existingTitle) {
|
if (existingTitle) {
|
||||||
await pool.query(
|
await pool.query(
|
||||||
"INSERT INTO ai_chat_messages (session_id, user_id, role, content) VALUES (?, ?, 'assistant', ?)",
|
"INSERT INTO ai_chat_messages (session_id, user_id, role, content,thinking) VALUES (?, ?, 'assistant', ?,?)",
|
||||||
[sessId, userId || null, llmText]
|
[sessId, userId || null, llmText,sceneText]
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
@@ -1709,9 +1722,10 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
|||||||
);
|
);
|
||||||
console.log("生成的标题:", title);
|
console.log("生成的标题:", title);
|
||||||
|
|
||||||
|
|
||||||
await pool.query(
|
await pool.query(
|
||||||
"INSERT INTO ai_chat_messages (session_id, user_id, role, content, title) VALUES (?, ?, 'assistant', ?, ?)",
|
"INSERT INTO ai_chat_messages (session_id, user_id, role, content, title,thinking) VALUES (?, ?, 'assistant', ?, ?,?)",
|
||||||
[sessId, userId || null, llmText, title]
|
[sessId, userId || null, llmText, title,sceneText]
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("生成标题失败:", err.message);
|
console.error("生成标题失败:", err.message);
|
||||||
|
|||||||
Reference in New Issue
Block a user