From 314c60d0aea73a0c36135c6a78e35457373e17c3 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Thu, 2 Jan 2025 20:51:45 +0800 Subject: [PATCH] fix: bym optimizing --- apps/bym.js | 59 +++++++++++++------ utils/tools/SendAvatarTool.js | 2 +- utils/tools/SendBilibiliTool.js | 2 +- .../SendMessageToSpecificGroupOrUserTool.js | 2 +- utils/tools/SendMusicTool.js | 2 +- utils/tools/SendPictureTool.js | 2 +- 6 files changed, 46 insertions(+), 23 deletions(-) diff --git a/apps/bym.js b/apps/bym.js index 7d1db88..fe1f52a 100644 --- a/apps/bym.js +++ b/apps/bym.js @@ -17,6 +17,7 @@ import { JinyanTool } from '../utils/tools/JinyanTool.js' import { KickOutTool } from '../utils/tools/KickOutTool.js' import { SetTitleTool } from '../utils/tools/SetTitleTool.js' import {SerpTool} from '../utils/tools/SerpTool.js' +import { SendMessageToSpecificGroupOrUserTool } from '../utils/tools/SendMessageToSpecificGroupOrUserTool.js' export class bym extends plugin { constructor () { @@ -72,9 +73,10 @@ export class bym extends plugin { if (Config.assistantLabel && e.msg?.includes(Config.assistantLabel)) { prop = -1 } - if (e.msg?.endsWith('?')) { - prop = prop / 10 - } + // 去掉吧 频率有点逆天 + // if (e.msg?.endsWith('?')) { + // prop = prop / 10 + // } let fuck = false let candidate = Config.bymPreset @@ -85,7 +87,7 @@ export class bym extends plugin { if (prop < Config.bymRate) { logger.info('random chat hit') let chats = await getChatHistoryGroup(e, 20) - opt.system = `你的名字是“${Config.assistantLabel}”,你在一个qq群里,群号是${group},当前和你说话的人群名片是${card}, qq号是${sender}, 请你结合用户的发言和聊天记录作出回应,要求表现得随性一点,最好参与讨论,混入其中。不要过分插科打诨,不知道说什么可以复读群友的话。要求你做搜索、发图、发视频和音乐等操作时要使用工具。不可以直接发[图片]这样蒙混过关。要求优先使用中文进行对话。` + + opt.system = `你的名字是“${Config.assistantLabel}”,你在一个qq群里,群号是${group},当前和你说话的人群名片是${card}, qq号是${sender}, 请你结合用户的发言和聊天记录作出回应,要求表现得随性一点,最好参与讨论,混入其中。不要过分插科打诨,不知道说什么可以复读群友的话。要求你做搜索、发图、发视频和音乐等操作时要使用工具。不可以直接发[图片]这样蒙混过关。要求优先使用中文进行对话。如果此时不需要自己说话,可以只回复` + candidate + '以下是聊天记录:' + chats .map(chat => { @@ -116,7 +118,8 @@ export class bym extends plugin { new SendMusicTool(), new SendPictureTool(), new WebsiteTool(), - new WeatherTool() + new WeatherTool(), + new SendMessageToSpecificGroupOrUserTool() ] if (Config.azSerpKey) { tools.push(new SerpTool()) @@ -133,7 +136,7 @@ export class bym extends plugin { // console.log(JSON.stringify(opt)) let rsp = await client.sendMessage(e.msg, opt) let text = rsp.text - let texts = text.split(/(? { + setTimeout(() => { + resolve() + }, Math.min(t.length * 200, 3000)) }) } - await new Promise((resolve, reject) => { - setTimeout(() => { - resolve() - }, Math.min(t.length * 200, 3000)) - }) } } return false } } + +/** + * 过滤 + * @param msg + */ +function filterResponseChunk (msg) { + if (!msg) { + return false + } + if (msg.trim() === '```') { + return false + } + if (msg.trim() === '') { + return false + } + return msg +} diff --git a/utils/tools/SendAvatarTool.js b/utils/tools/SendAvatarTool.js index ed6fde4..5c076ae 100644 --- a/utils/tools/SendAvatarTool.js +++ b/utils/tools/SendAvatarTool.js @@ -41,5 +41,5 @@ export class SendAvatarTool extends AbstractTool { return `the ${pictures.length > 1 ? 'users: ' + qq + '\'s avatar' : 'avatar'} has been sent to group ${target}` } - description = 'Useful when you want to send the user avatar to the group. Note that if you want to process user\'s avatar, it is advisable to utilize the ProcessPictureTool and input the qq of target user.' + description = 'Useful when you want to send the user avatar to the group. Note that if you want to process user\'s avatar, it is advisable to utilize the ProcessPictureTool and input the qq of target user. If no extra description needed, just reply at the next turn' } diff --git a/utils/tools/SendBilibiliTool.js b/utils/tools/SendBilibiliTool.js index d430628..9a47952 100644 --- a/utils/tools/SendBilibiliTool.js +++ b/utils/tools/SendBilibiliTool.js @@ -63,7 +63,7 @@ export class SendVideoTool extends AbstractTool { } } - description = 'Useful when you are allowed to send a video. You must use searchVideo to get search result and choose one video and get its id' + description = 'Useful when you are allowed to send a video. You must use searchVideo to get search result and choose one video and get its id. If no extra description needed, just reply at the next turn' } export async function getBilibili (bvid) { diff --git a/utils/tools/SendMessageToSpecificGroupOrUserTool.js b/utils/tools/SendMessageToSpecificGroupOrUserTool.js index b6ff4ae..d445d3f 100644 --- a/utils/tools/SendMessageToSpecificGroupOrUserTool.js +++ b/utils/tools/SendMessageToSpecificGroupOrUserTool.js @@ -46,5 +46,5 @@ export class SendMessageToSpecificGroupOrUserTool extends AbstractTool { } } - description = 'Useful when you want to send a text message to specific user or group' + description = 'Useful when you want to send a text message to specific user or group. If no extra description needed, just reply at the next turn' } diff --git a/utils/tools/SendMusicTool.js b/utils/tools/SendMusicTool.js index 2554a92..e40aa0d 100644 --- a/utils/tools/SendMusicTool.js +++ b/utils/tools/SendMusicTool.js @@ -34,5 +34,5 @@ export class SendMusicTool extends AbstractTool { } } - description = 'Useful when you want to share music. You must use searchMusic first to get the music id' + description = 'Useful when you want to share music. You must use searchMusic first to get the music id. If no extra description needed, just reply at the next turn' } diff --git a/utils/tools/SendPictureTool.js b/utils/tools/SendPictureTool.js index 96eb2c3..dc9da3f 100644 --- a/utils/tools/SendPictureTool.js +++ b/utils/tools/SendPictureTool.js @@ -56,5 +56,5 @@ export class SendPictureTool extends AbstractTool { } } - description = 'Useful when you want to send one or more pictures.' + description = 'Useful when you want to send one or more pictures. If no extra description needed, just reply at the next turn' }