Skip to content

Commit

Permalink
fix: 修复上下文聊天大于20时记录顺序错误的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ikechan8370 committed Feb 13, 2025
1 parent 2ad77d8 commit 88360ec
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions apps/bym.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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}:),禁止重复聊天记录。`
Expand Down
2 changes: 1 addition & 1 deletion model/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import { BingAIClient } from '../client/CopilotAIClient.js'
import Keyv from 'keyv'
import crypto from 'crypto'

const roleMap = {
export const roleMap = {
owner: 'group owner',
admin: 'group administrator'
}
Expand Down
8 changes: 4 additions & 4 deletions utils/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export async function getChatHistoryGroup (e, num) {
if (!chatHistory || chatHistory.length === 0) {
break
}
chats.push(...chatHistory)
if (seq === chatHistory[0].seq || seq === chatHistory[0].message_id) {
chats.push(...chatHistory.reverse())
if (seq === chatHistory[chatHistory.length - 1].seq || seq === chatHistory[chatHistory.length - 1].message_id) {
break
}
seq = chatHistory[0].seq || chatHistory[0].message_id
seq = chatHistory[chatHistory.length - 1].seq || chatHistory[chatHistory.length - 1].message_id
}
chats = chats.slice(0, num)
chats = chats.slice(0, num).reverse()
try {
let mm = await e.bot.gml
for (const chat of chats) {
Expand Down

0 comments on commit 88360ec

Please sign in to comment.