深度思考finish
This commit is contained in:
26
server2.js
26
server2.js
@@ -892,7 +892,7 @@ app.get("/history", async (req, res) => {
|
||||
|
||||
// 查询数据库
|
||||
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]
|
||||
);
|
||||
|
||||
@@ -1391,6 +1391,8 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
||||
return res.status(400).json({ error: "对话次数已用完,请完成账号注册" });
|
||||
}
|
||||
}
|
||||
|
||||
console.log("====== 开始图像分析11... ======");
|
||||
|
||||
const { requestId } = req.body;
|
||||
|
||||
@@ -1401,6 +1403,7 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
||||
"X-Accel-Buffering": "no",
|
||||
});
|
||||
res.flushHeaders?.();
|
||||
res.socket.setNoDelay(true); // 禁用缓冲,实时推送
|
||||
let aborted = false;
|
||||
req.on("close", () => {
|
||||
console.log("🔴 前端断开连接,停止整个分析流程");
|
||||
@@ -1442,6 +1445,8 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
||||
"SELECT role, content, image_base64 FROM ai_chat_messages WHERE session_id = ? AND user_id = ? ORDER BY created_at ASC",
|
||||
[sessId, userId || null]
|
||||
);
|
||||
|
||||
console.log("====== 开始图像分析22... ======");
|
||||
|
||||
// 构建历史消息数组
|
||||
const historyMessages = historyRows.slice(-MAX_HISTORY).map(row => {
|
||||
@@ -1469,6 +1474,8 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
||||
|
||||
return message;
|
||||
});
|
||||
|
||||
console.log("====== 开始图像分析33... ======");
|
||||
|
||||
// ------------------ 保存用户提问 ------------------
|
||||
await pool.query(
|
||||
@@ -1478,6 +1485,8 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
||||
|
||||
// ------------------ 图像分析 ------------------
|
||||
let sceneText = "";
|
||||
|
||||
console.log("====== 开始图像分析55... ======");
|
||||
|
||||
// If an image is uploaded, start with image analysis
|
||||
if (imageBase64) {
|
||||
@@ -1530,9 +1539,11 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
||||
].filter(Boolean),
|
||||
},
|
||||
];
|
||||
|
||||
console.log("====== 开始图像分析666... ======");
|
||||
|
||||
const completion = await client.chat.completions.create({
|
||||
model: "gpt-4.1-mini",
|
||||
model: "gpt-4.1",
|
||||
stream: true,
|
||||
messages: imageAnalysisMessages
|
||||
});
|
||||
@@ -1687,10 +1698,12 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
||||
console.log("====== 最终分析结束 ======");
|
||||
|
||||
// ------------------ Save Results to Database ------------------
|
||||
|
||||
sceneText += thinkingText;
|
||||
if (existingTitle) {
|
||||
await pool.query(
|
||||
"INSERT INTO ai_chat_messages (session_id, user_id, role, content) VALUES (?, ?, 'assistant', ?)",
|
||||
[sessId, userId || null, llmText]
|
||||
"INSERT INTO ai_chat_messages (session_id, user_id, role, content,thinking) VALUES (?, ?, 'assistant', ?,?)",
|
||||
[sessId, userId || null, llmText,sceneText]
|
||||
);
|
||||
} else {
|
||||
try {
|
||||
@@ -1709,9 +1722,10 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
|
||||
);
|
||||
console.log("生成的标题:", title);
|
||||
|
||||
|
||||
await pool.query(
|
||||
"INSERT INTO ai_chat_messages (session_id, user_id, role, content, title) VALUES (?, ?, 'assistant', ?, ?)",
|
||||
[sessId, userId || null, llmText, title]
|
||||
"INSERT INTO ai_chat_messages (session_id, user_id, role, content, title,thinking) VALUES (?, ?, 'assistant', ?, ?,?)",
|
||||
[sessId, userId || null, llmText, title,sceneText]
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("生成标题失败:", err.message);
|
||||
|
||||
Reference in New Issue
Block a user