首轮不注入注意力prompt

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

View File

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