首轮不注入注意力prompt

This commit is contained in:
Vinlic 2024-04-08 22:26:05 +08:00
parent f5bea5ea68
commit 9fd7ae890b

View File

@ -366,20 +366,23 @@ function messagesPrepare(messages: any[]) {
let latestMessage = messages[messages.length - 1]; let latestMessage = messages[messages.length - 1];
let hasFileOrImage = Array.isArray(latestMessage.content) let hasFileOrImage = Array.isArray(latestMessage.content)
&& latestMessage.content.some(v => (typeof v === 'object' && ['file', 'image_url'].includes(v['type']))); && latestMessage.content.some(v => (typeof v === 'object' && ['file', 'image_url'].includes(v['type'])));
if (hasFileOrImage) { // 第二轮开始注入system prompt
let newFileMessage = { if (messages.length > 2) {
"content": "关注用户最新发送文件和消息", if (hasFileOrImage) {
"role": "system" let newFileMessage = {
}; "content": "关注用户最新发送文件和消息",
messages.splice(messages.length - 1, 0, newFileMessage); "role": "system"
logger.info("注入提升尾部文件注意力system prompt"); };
} else if (messages.length > 2) { messages.splice(messages.length - 1, 0, newFileMessage);
let newTextMessage = { logger.info("注入提升尾部文件注意力system prompt");
"content": "关注用户最新的消息", } else {
"role": "system" let newTextMessage = {
}; "content": "关注用户最新的消息",
messages.splice(messages.length - 1, 0, newTextMessage); "role": "system"
logger.info("注入提升尾部消息注意力system prompt"); };
messages.splice(messages.length - 1, 0, newTextMessage);
logger.info("注入提升尾部消息注意力system prompt");
}
} }
const content = messages.reduce((content, message) => { const content = messages.reduce((content, message) => {