From 2959a569785ccafa52ff8c72b9b9128592db1eeb Mon Sep 17 00:00:00 2001 From: Song367 <601337784@qq.com> Date: Thu, 7 Aug 2025 17:56:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9history?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chat_history.json | 27 ++++++++++++++++++++++++++- src/chat_with_audio.js | 7 ++++--- src/message_history.js | 12 ++++++------ 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/chat_history.json b/chat_history.json index 0637a08..b81f060 100644 --- a/chat_history.json +++ b/chat_history.json @@ -1 +1,26 @@ -[] \ No newline at end of file +[ + { + "role": "user", + "content": "好了好了,在干嘛?" + }, + { + "role": "assistant", + "content": "到公司咯……正在喝咖啡,宝贝,想我没?" + }, + { + "role": "user", + "content": "没有没有。" + }, + { + "role": "assistant", + "content": "小淘气,就知道逗我……诶,你今天打算干嘛呀?" + }, + { + "role": "user", + "content": "好了,说话说话。" + }, + { + "role": "assistant", + "content": "好好好,一直都在说呀……是不是信号不好,没听清?" + } +] \ No newline at end of file diff --git a/src/chat_with_audio.js b/src/chat_with_audio.js index 2b6f4b1..a68247f 100644 --- a/src/chat_with_audio.js +++ b/src/chat_with_audio.js @@ -26,12 +26,13 @@ async function initializeHistoryMessage(recentCount = 5) { const data = await response.json(); historyMessage = data.messages || []; isInitialized = true; - console.log("历史消息初始化完成:", historyMessage.length, "条消息"); + console.log("历史消息初始化完成:", historyMessage.length, "条消息", historyMessage); + return historyMessage; } catch (error) { console.error('获取历史消息失败,使用默认格式:', error); historyMessage = [ - { role: 'system', content: 'You are a helpful assistant.' } + // { role: 'system', content: 'You are a helpful assistant.' } ]; isInitialized = true; return historyMessage; @@ -42,7 +43,7 @@ async function initializeHistoryMessage(recentCount = 5) { function getCurrentHistoryMessage() { if (!isInitialized) { console.warn('历史消息未初始化,返回默认消息'); - return [{ role: 'system', content: 'You are a helpful assistant.' }]; + return []; } return [...historyMessage]; // 返回副本,避免外部修改 } diff --git a/src/message_history.js b/src/message_history.js index 91de32f..22df403 100644 --- a/src/message_history.js +++ b/src/message_history.js @@ -56,12 +56,12 @@ class MessageHistory { const messages = []; // 添加系统消息 - if (includeSystem) { - messages.push({ - role: 'system', - content: 'You are a helpful assistant.' - }); - } + // if (includeSystem) { + // messages.push({ + // role: 'system', + // content: 'You are a helpful assistant.' + // }); + // } // 获取最近的对话历史 const recentMessages = this.messages.slice(-recentCount * 2); // 用户+助手成对出现