注释title生成

This commit is contained in:
2025-11-24 14:29:50 +08:00
parent fc5ef75510
commit 3f8fff331f

View File

@@ -1031,8 +1031,11 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
// 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) { if (delta)
{
for (const ch of delta)
{
res.write(`data: ${JSON.stringify({ type: "llm", content: ch })}\n\n`); res.write(`data: ${JSON.stringify({ type: "llm", content: ch })}\n\n`);
await new Promise(r => setTimeout(r, 0)); // 控制渲染节奏 await new Promise(r => setTimeout(r, 0)); // 控制渲染节奏
} }
@@ -1041,8 +1044,9 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
// 保存 LLM 输出到数据库 // 保存 LLM 输出到数据库
/* 加标题需要异步,且在会话开始时就进行 */
// try { // try
// {
// const titlePrompt = `请根据以下对话内容生成一个简短的标题(不超过15字): // const titlePrompt = `请根据以下对话内容生成一个简短的标题(不超过15字):
// 用户问题: ${userPrompt} // 用户问题: ${userPrompt}
// AI回答: ${llmText}`; // AI回答: ${llmText}`;
@@ -1063,17 +1067,20 @@ app.post("/analyze", upload.single("file"), async (req, res) => {
// console.log("生成的标题:", title); // console.log("生成的标题:", title);
// // 保存到数据库(建议你给 ai_chat_messages 表新增一列 title,或者单独建一张会话表) // // 保存到数据库(建议你给 ai_chat_messages 表新增一列 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) VALUES (?, ?, 'assistant', ?,?)",
// [sessId, userId || null, llmText,title] // // [sessId, userId || null, llmText,title]
// ); // // );
// } // }
// catch (err) { // catch (err)
// {
// console.error("生成标题失败:", err.message); // console.error("生成标题失败:", err.message);
// } // }
await pool.query(
"INSERT INTO ai_chat_messages (session_id, user_id, role, content) VALUES (?, ?, 'assistant', ?)",
[sessId, userId || null, llmText]
);
res.write("data: [DONE]\n\n"); res.write("data: [DONE]\n\n");
res.end(); res.end();