fix: 修复上下文聊天大于20时记录顺序错误的问题

This commit is contained in:
ikechan8370 2025-02-14 00:14:23 +08:00
parent 2ad77d8112
commit 88360ecc42
3 changed files with 9 additions and 8 deletions

View file

@ -2,7 +2,8 @@ import { Config } from '../utils/config.js'
import { getChatHistoryGroup } from '../utils/chat.js'
import { convertFaces } from '../utils/face.js'
import { customSplitRegex, filterResponseChunk } from '../utils/text.js'
import core from '../model/core.js'
import core, {roleMap} from '../model/core.js'
import {formatDate} from '../utils/common.js'
export class bym extends plugin {
constructor () {
@ -54,13 +55,13 @@ export class bym extends plugin {
}
if (prop < Config.bymRate) {
logger.info('random chat hit')
let chats = await getChatHistoryGroup(e, 20)
let chats = await getChatHistoryGroup(e, Config.groupContextLength)
let system = `你的名字是“${Config.assistantLabel}你在一个qq群里群号是${group},当前和你说话的人群名片是${card}, qq号是${sender}, 请你结合用户的发言和聊天记录作出回应,要求表现得随性一点,最好参与讨论,混入其中。不要过分插科打诨,不知道说什么可以复读群友的话。要求你做搜索、发图、发视频和音乐等操作时要使用工具。不可以直接发[图片]这样蒙混过关。要求优先使用中文进行对话。如果此时不需要自己说话,可以只回复<EMPTY>` +
candidate +
'以下是聊天记录:' + chats
.map(chat => {
let sender = chat.sender || chat || {}
return `${sender.card || sender.nickname}(${sender.user_id}) ${chat.raw_message}`
return `${sender.card || sender.nickname}】(qq${sender.user_id}, ${roleMap[sender.role] || 'normal user'}${sender.area ? 'from ' + sender.area + ', ' : ''} ${sender.age} years old, 群头衔:${sender.title}, gender: ${sender.sex}, time${formatDate(new Date(chat.time * 1000))}${chat.raw_message}`
})
.join('\n') +
`\n你的回复应该尽可能简练,像人类一样随意,不要附加任何奇怪的东西,如聊天记录的格式(比如${Config.assistantLabel}:),禁止重复聊天记录。`