修改history
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 2m50s
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 2m50s
This commit is contained in:
parent
e281545435
commit
2959a56978
@ -1 +1,26 @@
|
|||||||
[]
|
[
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": "好了好了,在干嘛?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "到公司咯……正在喝咖啡,宝贝,想我没?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": "没有没有。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "小淘气,就知道逗我……诶,你今天打算干嘛呀?"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": "好了,说话说话。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "好好好,一直都在说呀……是不是信号不好,没听清?"
|
||||||
|
}
|
||||||
|
]
|
||||||
@ -26,12 +26,13 @@ async function initializeHistoryMessage(recentCount = 5) {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
historyMessage = data.messages || [];
|
historyMessage = data.messages || [];
|
||||||
isInitialized = true;
|
isInitialized = true;
|
||||||
console.log("历史消息初始化完成:", historyMessage.length, "条消息");
|
console.log("历史消息初始化完成:", historyMessage.length, "条消息", historyMessage);
|
||||||
|
|
||||||
return historyMessage;
|
return historyMessage;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取历史消息失败,使用默认格式:', error);
|
console.error('获取历史消息失败,使用默认格式:', error);
|
||||||
historyMessage = [
|
historyMessage = [
|
||||||
{ role: 'system', content: 'You are a helpful assistant.' }
|
// { role: 'system', content: 'You are a helpful assistant.' }
|
||||||
];
|
];
|
||||||
isInitialized = true;
|
isInitialized = true;
|
||||||
return historyMessage;
|
return historyMessage;
|
||||||
@ -42,7 +43,7 @@ async function initializeHistoryMessage(recentCount = 5) {
|
|||||||
function getCurrentHistoryMessage() {
|
function getCurrentHistoryMessage() {
|
||||||
if (!isInitialized) {
|
if (!isInitialized) {
|
||||||
console.warn('历史消息未初始化,返回默认消息');
|
console.warn('历史消息未初始化,返回默认消息');
|
||||||
return [{ role: 'system', content: 'You are a helpful assistant.' }];
|
return [];
|
||||||
}
|
}
|
||||||
return [...historyMessage]; // 返回副本,避免外部修改
|
return [...historyMessage]; // 返回副本,避免外部修改
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,12 +56,12 @@ class MessageHistory {
|
|||||||
const messages = [];
|
const messages = [];
|
||||||
|
|
||||||
// 添加系统消息
|
// 添加系统消息
|
||||||
if (includeSystem) {
|
// if (includeSystem) {
|
||||||
messages.push({
|
// messages.push({
|
||||||
role: 'system',
|
// role: 'system',
|
||||||
content: 'You are a helpful assistant.'
|
// content: 'You are a helpful assistant.'
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 获取最近的对话历史
|
// 获取最近的对话历史
|
||||||
const recentMessages = this.messages.slice(-recentCount * 2); // 用户+助手成对出现
|
const recentMessages = this.messages.slice(-recentCount * 2); // 用户+助手成对出现
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user