From afa456f044368892b73d25b70380e21605927191 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Sat, 15 Feb 2025 23:08:03 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=E9=94=99=E8=AF=AF=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E9=9D=9E=E6=96=87=E6=9C=AC=E6=B6=88=E6=81=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/bym.js | 4 ++-- utils/text.js | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/bym.js b/apps/bym.js index c066b05..aa7b56c 100644 --- a/apps/bym.js +++ b/apps/bym.js @@ -2,8 +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, {roleMap} from '../model/core.js' -import {formatDate} from '../utils/common.js' +import core, { roleMap } from '../model/core.js' +import { formatDate } from '../utils/common.js' export class bym extends plugin { constructor () { diff --git a/utils/text.js b/utils/text.js index a617e1d..7216ee6 100644 --- a/utils/text.js +++ b/utils/text.js @@ -3,9 +3,12 @@ * @param msg */ export function filterResponseChunk (msg) { - if (!msg || typeof msg !== 'string') { + if (!msg) { return false } + if (typeof msg !== 'string') { + return msg + } if (!msg.trim()) { return false } From 9930e53a03cac39e2536f5167390c3e16a6e9762 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Sat, 15 Feb 2025 23:28:14 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=E8=81=8A=E5=A4=A9=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/bym.js | 4 +++- model/core.js | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/apps/bym.js b/apps/bym.js index aa7b56c..b9d271a 100644 --- a/apps/bym.js +++ b/apps/bym.js @@ -81,7 +81,9 @@ export class bym extends plugin { replyPureTextCallback: msg => { msg = filterResponseChunk(msg) msg && e.reply(msg) - } + }, + // 上下文在bym.js里构造,简化版。 + enableGroupContext: false } }) // let rsp = await client.sendMessage(e.msg, opt) diff --git a/model/core.js b/model/core.js index bfe7915..e749c65 100644 --- a/model/core.js +++ b/model/core.js @@ -62,8 +62,8 @@ export const roleMap = { const defaultPropmtPrefix = ', a large language model trained by OpenAI. You answer as concisely as possible for each response (e.g. don’t be verbose). It is very important that you answer as concisely as possible, so please remember this. If you are generating a list, do not have too many items. Keep the number of items short.' -async function handleSystem (e, system) { - if (Config.enableGroupContext) { +async function handleSystem (e, system, settings) { + if (settings.enableGroupContext) { try { let opt = {} opt.groupId = e.group_id @@ -126,7 +126,8 @@ class Core { xh: Config.xhPrompt }, settings: { - replyPureTextCallback: undefined + replyPureTextCallback: undefined, + enableGroupContext: Config.enableGroupContext } }) { if (!conversation) { @@ -160,14 +161,14 @@ class Core { } }) let system = opt.system.bing - if (Config.enableGroupContext && e.isGroup) { + if (opt.settings.enableGroupContext && e.isGroup) { let chats = await getChatHistoryGroup(e, Config.groupContextLength) const namePlaceholder = '[name]' const defaultBotName = 'Copilot' const groupContextTip = Config.groupContextTip let botName = e.isGroup ? (e.group.pickMember(getUin(e)).card || e.group.pickMember(getUin(e)).nickname) : e.bot.nickname system = system.replaceAll(namePlaceholder, botName || defaultBotName) + - ((Config.enableGroupContext && e.group_id) ? groupContextTip : '') + ((opt.settings.enableGroupContext && e.group_id) ? groupContextTip : '') system += 'Attention, you are currently chatting in a qq group, then one who asks you now is' + `${e.sender.card || e.sender.nickname}(${e.sender.user_id}).` system += `the group name is ${e.group.name || e.group_name}, group id is ${e.group_id}.` system += `Your nickname is ${botName} in the group,` @@ -434,7 +435,7 @@ class Core { option.completionParams = {} } promptAddition && (prompt += promptAddition) - option.systemMessage = await handleSystem(e, opts.systemMessage) + option.systemMessage = await handleSystem(e, opts.systemMessage, opt.settings) if (Config.enableChatSuno) { option.systemMessage += '如果我要求你生成音乐或写歌,你需要回复适合Suno生成音乐的信息。请使用Verse、Chorus、Bridge、Outro和End等关键字对歌词进行分段,如[Verse 1]。音乐信息需要使用markdown包裹的JSON格式回复给我,结构为```json{"option": "Suno", "tags": "style", "title": "title of the song", "lyrics": "lyrics"}```。' } @@ -580,14 +581,14 @@ class Core { client.addTools(tools) } let system = opt.system.gemini - if (Config.enableGroupContext && e.isGroup) { + if (opt.settings.enableGroupContext && e.isGroup) { let chats = await getChatHistoryGroup(e, Config.groupContextLength) const namePlaceholder = '[name]' const defaultBotName = 'GeminiPro' const groupContextTip = Config.groupContextTip let botName = e.isGroup ? (e.group.pickMember(getUin(e)).card || e.group.pickMember(getUin(e)).nickname) : e.bot.nickname system = system.replaceAll(namePlaceholder, botName || defaultBotName) + - ((Config.enableGroupContext && e.group_id) ? groupContextTip : '') + ((opt.settings.enableGroupContext && e.group_id) ? groupContextTip : '') system += 'Attention, you are currently chatting in a qq group, then one who asks you now is' + `${e.sender.card || e.sender.nickname}(${e.sender.user_id}).` system += `the group name is ${e.group.name || e.group_name}, group id is ${e.group_id}.` system += `Your nickname is ${botName} in the group,` @@ -631,7 +632,7 @@ class Core { Current date: ${currentDate}` let maxModelTokens = getMaxModelTokens(completionParams.model) // let system = promptPrefix - let system = await handleSystem(e, promptPrefix, maxModelTokens) + let system = await handleSystem(e, promptPrefix, opt.settings) if (Config.enableChatSuno) { system += 'If I ask you to generate music or write songs, you need to reply with information suitable for Suno to generate music. Please use keywords such as Verse, Chorus, Bridge, Outro, and End to segment the lyrics, such as [Verse 1], The returned song information needs to be wrapped in JSON format and sent to me in Markdown format. The message structure is ` ` JSON {"option": "Suno", "tags": "style", "title": "title of The Song", "lyrics": "lyrics"} `.' } From c3eb8ac5dbf56c66acefea73faabea6a407da134 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Sat, 15 Feb 2025 23:39:45 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E8=81=8A=E5=A4=A9=E8=AE=B0=E5=BD=95?= =?UTF-8?q?bug=EF=BC=9B=E5=88=A0=E9=99=A4=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/bym.js | 10 ++-------- client/CopilotAIClient.js | 4 +++- client/CustomGoogleGeminiClient.js | 2 +- model/core.js | 4 +++- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/apps/bym.js b/apps/bym.js index b9d271a..41b86f5 100644 --- a/apps/bym.js +++ b/apps/bym.js @@ -55,15 +55,9 @@ export class bym extends plugin { } if (prop < Config.bymRate) { logger.info('random chat hit') - let chats = await getChatHistoryGroup(e, Config.groupContextLength) + // let chats = await getChatHistoryGroup(e, Config.groupContextLength) let system = `你的名字是“${Config.assistantLabel}”,你在一个qq群里,群号是${group},当前和你说话的人群名片是${card}, qq号是${sender}, 请你结合用户的发言和聊天记录作出回应,要求表现得随性一点,最好参与讨论,混入其中。不要过分插科打诨,不知道说什么可以复读群友的话。要求你做搜索、发图、发视频和音乐等操作时要使用工具。不可以直接发[图片]这样蒙混过关。要求优先使用中文进行对话。如果此时不需要自己说话,可以只回复` + candidate + - '以下是聊天记录:' + chats - .map(chat => { - let sender = chat.sender || chat || {} - 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}:),禁止重复聊天记录。` let rsp = await core.sendMessage(e.msg, {}, Config.bymMode, e, { @@ -83,7 +77,7 @@ export class bym extends plugin { msg && e.reply(msg) }, // 上下文在bym.js里构造,简化版。 - enableGroupContext: false + enableGroupContext: Config.enableGroupContext } }) // let rsp = await client.sendMessage(e.msg, opt) diff --git a/client/CopilotAIClient.js b/client/CopilotAIClient.js index 8295353..6ff650f 100644 --- a/client/CopilotAIClient.js +++ b/client/CopilotAIClient.js @@ -121,7 +121,9 @@ export class BingAIClient { this.ws.once('message', (data) => { clearTimeout(timeout) // 清除超时定时器 const message = JSON.parse(data) - logger.info(data) + if (this.debug) { + logger.info(data) + } if (message.event === 'challenge') { logger.warn('遇到turnstile验证码,尝试使用2captcha解决') // 如果收到 challenge,处理挑战 diff --git a/client/CustomGoogleGeminiClient.js b/client/CustomGoogleGeminiClient.js index ec3e771..87ef625 100644 --- a/client/CustomGoogleGeminiClient.js +++ b/client/CustomGoogleGeminiClient.js @@ -250,7 +250,7 @@ export class CustomGoogleGeminiClient extends GoogleGeminiClient { delete content.conversationId }) if (this.debug) { - logger.info(JSON.stringify(body)) + logger.debug(JSON.stringify(body)) } let result = await newFetch(url, { method: 'POST', diff --git a/model/core.js b/model/core.js index e749c65..3c86c73 100644 --- a/model/core.js +++ b/model/core.js @@ -152,7 +152,9 @@ class Core { messages: [], createdAt: Date.now() } - logger.info(JSON.stringify(conversations)) + if (Config.debug) { + logger.debug(JSON.stringify(conversations)) + } const previousCachedMessages = SydneyAIClient.getMessagesForConversation(conversations.messages, conversation.parentMessageId) .map((message) => { return { From f619035e528987a81c786f9802921d69f51a1ef9 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Sat, 15 Feb 2025 23:42:28 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=E4=BC=AA=E4=BA=BA=E9=99=90=E5=88=B6?= =?UTF-8?q?=E5=BC=80=E5=90=AF=E4=B8=8A=E4=B8=8B=E6=96=87=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E7=84=B6=E7=AC=A8=E6=AD=BB=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/bym.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/bym.js b/apps/bym.js index 41b86f5..0fab4f2 100644 --- a/apps/bym.js +++ b/apps/bym.js @@ -76,8 +76,8 @@ export class bym extends plugin { msg = filterResponseChunk(msg) msg && e.reply(msg) }, - // 上下文在bym.js里构造,简化版。 - enableGroupContext: Config.enableGroupContext + // 强制打开上下文,不然伪人笨死了 + enableGroupContext: true } }) // let rsp = await client.sendMessage(e.msg, opt)