From ac304e0ed3e56fbc8335981ed5f3b93223b7ff1d Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Sat, 3 Aug 2024 13:24:01 +0800 Subject: [PATCH 1/9] =?UTF-8?q?fix:=20gemini=E7=A6=81=E8=A8=80=E8=B6=8A?= =?UTF-8?q?=E6=9D=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/CustomGoogleGeminiClient.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/CustomGoogleGeminiClient.js b/client/CustomGoogleGeminiClient.js index dfe79865..b0e1ba38 100644 --- a/client/CustomGoogleGeminiClient.js +++ b/client/CustomGoogleGeminiClient.js @@ -232,9 +232,11 @@ export class CustomGoogleGeminiClient extends GoogleGeminiClient { } else { // execute function try { + let isAdmin = ['admin', 'owner'].includes(this.e.sender.role) + let isOwner = ['owner'].includes(this.e.sender.role) let args = Object.assign(functionCall.args, { - isAdmin: this.e.group?.is_admin, - isOwner: this.e.group?.is_owner, + isAdmin, + isOwner, sender: this.e.sender, mode: 'gemini' }) From beaec147b5eb8cc3ad1c923cd08f1ceecbf6d73e Mon Sep 17 00:00:00 2001 From: misaka20002 <40714502+misaka20002@users.noreply.github.com> Date: Sat, 3 Aug 2024 21:13:01 +0800 Subject: [PATCH 2/9] =?UTF-8?q?gemini=E6=99=BA=E8=83=BD=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=E4=B8=BB=E4=BA=BA=E5=8F=AF=E4=BD=BF=E7=94=A8bot?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E7=A6=81=E8=A8=80=E6=9D=83=E9=99=90?= =?UTF-8?q?=20(#708)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/CustomGoogleGeminiClient.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/CustomGoogleGeminiClient.js b/client/CustomGoogleGeminiClient.js index b0e1ba38..22d5abe8 100644 --- a/client/CustomGoogleGeminiClient.js +++ b/client/CustomGoogleGeminiClient.js @@ -232,8 +232,8 @@ export class CustomGoogleGeminiClient extends GoogleGeminiClient { } else { // execute function try { - let isAdmin = ['admin', 'owner'].includes(this.e.sender.role) - let isOwner = ['owner'].includes(this.e.sender.role) + let isAdmin = ['admin', 'owner'].includes(this.e.sender.role) || (this.e.group?.is_admin && this.e.isMaster) + let isOwner = ['owner'].includes(this.e.sender.role) || (this.e.group?.is_owner && this.e.isMaster) let args = Object.assign(functionCall.args, { isAdmin, isOwner, From b87bf7772877925189a5cfde726315d833f01b1a Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Tue, 6 Aug 2024 11:20:17 +0800 Subject: [PATCH 3/9] fix: try to fix openai version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c6bc3574..50f90f54 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "lodash": "^4.17.21", "microsoft-cognitiveservices-speech-sdk": "1.32.0", "node-fetch": "^3.3.1", - "openai": "^3.2.1", + "openai": "3.2.1", "p-timeout": "^6.1.2", "quick-lru": "6.1.1", "random": "^4.1.0", From 3822da62b0a9778a361d7d96c5cd230fd84f8bc2 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Fri, 11 Oct 2024 21:43:04 +0800 Subject: [PATCH 4/9] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c9bfe2d4..9f32b81d 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ +> 由于相关领域发展快速,迭代较多,本文档有部分过时内容,不确定的问题可以开discussion或加群问群里的大佬们哦 ### 推荐的相关文档和参考资料 本README From f0a17dc422d0896fe34573c3b86749b0ca799f1b Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Fri, 11 Oct 2024 22:15:05 +0800 Subject: [PATCH 5/9] fix: #713 --- apps/button.js | 8 ++++++ apps/chat.js | 55 +++++++++++++++++++++----------------- client/OpenAILikeClient.js | 0 guoba.support.js | 12 ++++----- 4 files changed, 44 insertions(+), 31 deletions(-) delete mode 100644 client/OpenAILikeClient.js diff --git a/apps/button.js b/apps/button.js index 7bff6ff6..d443ba4b 100644 --- a/apps/button.js +++ b/apps/button.js @@ -53,6 +53,14 @@ export class ChatGPTButtonHandler extends plugin { }) } + /** + * 按钮处理器 + * @param e + * @param options + * @param reject + * @deprecated + * @return {Promise<{appid: number, rows: [{buttons: {render_data: {style: number, label, visited_label}, action: {data, permission: {type: number}, unsupport_tips: string, enter: boolean, type: number}, id: string}[]}]}|{appid: number, rows: [{buttons: [{render_data: {style: number, label: *, visited_label: *}, action: {data: *, permission: {type: number}, unsupport_tips: string, enter: boolean, type: number}, id: string},{render_data: {style: number, label: *, visited_label: *}, action: {data: *, permission: {type: number}, unsupport_tips: string, enter: boolean, type: number}, id: string},{render_data: {style: number, label: *, visited_label: *}, action: {data: *, permission: {type: number}, unsupport_tips: string, enter: boolean, type: number}, id: string}]}]}|{appid: number, rows: [{buttons: {render_data: {style: number, label, visited_label}, action: {data, permission: {type: number}, unsupport_tips: string, enter: boolean, type: number}, id: string}[]},{buttons: {render_data: {style: number, label, visited_label}, action: {data, permission: {type: number}, unsupport_tips: string, enter: boolean, type: number}, id: string}[]},{buttons: {render_data: {style: number, label, visited_label}, action: {data, permission: {type: number}, unsupport_tips: string, enter: boolean, type: number}, id: string}[]},{buttons: {render_data: {style: number, label, visited_label}, action: {data, permission: {type: number}, unsupport_tips: string, enter: boolean, type: number}, id: string}[]}]}|{appid: number, rows: [{buttons: {render_data: {style: number, label, visited_label}, action: {data, permission: {type: number}, unsupport_tips: string, enter: boolean, type: number}, id: string}[]},{buttons: {render_data: {style: number, label, visited_label}, action: {data, permission: {type: number}, unsupport_tips: string, enter: boolean, type: number}, id: string}[]},{buttons: {render_data: {style: number, label, visited_label}, action: {data, permission: {type: number}, unsupport_tips: string, enter: boolean, type: number}, id: string}[]}]}|null>} + */ async btnHandler (e, options, reject) { // logger.mark('[chatgpt按钮处理器]') if (!Config.enableMd) { diff --git a/apps/chat.js b/apps/chat.js index ee40ad08..2f934bef 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -74,43 +74,43 @@ export class chatgpt extends plugin { rule: [ { /** 命令正则匹配 */ - reg: '^#chat3[sS]*', + reg: '^#(图片)?chat3[sS]*', /** 执行方法 */ fnc: 'chatgpt3' }, { /** 命令正则匹配 */ - reg: '^#chat1[sS]*', + reg: '^#(图片)?chat1[sS]*', /** 执行方法 */ fnc: 'chatgpt1' }, { /** 命令正则匹配 */ - reg: '^#chatglm[sS]*', + reg: '^#(图片)?chatglm[sS]*', /** 执行方法 */ fnc: 'chatglm' }, { /** 命令正则匹配 */ - reg: '^#bing[sS]*', + reg: '^#(图片)?bing[sS]*', /** 执行方法 */ fnc: 'bing' }, { /** 命令正则匹配 */ - reg: '^#claude(2|3|.ai)[sS]*', + reg: '^#(图片)?claude(2|3|.ai)[sS]*', /** 执行方法 */ fnc: 'claude2' }, { /** 命令正则匹配 */ - reg: '^#claude[sS]*', + reg: '^#(图片)?claude[sS]*', /** 执行方法 */ fnc: 'claude' }, { /** 命令正则匹配 */ - reg: '^#xh[sS]*', + reg: '^#(图片)?xh[sS]*', /** 执行方法 */ fnc: 'xh' }, @@ -124,25 +124,25 @@ export class chatgpt extends plugin { }, { /** 命令正则匹配 */ - reg: '^#glm4[sS]*', + reg: '^#(图片)?glm4[sS]*', /** 执行方法 */ fnc: 'glm4' }, { /** 命令正则匹配 */ - reg: '^#qwen[sS]*', + reg: '^#(图片)?qwen[sS]*', /** 执行方法 */ fnc: 'qwen' }, { /** 命令正则匹配 */ - reg: '^#gemini[sS]*', + reg: '^#(图片)?gemini[sS]*', /** 执行方法 */ fnc: 'gemini' }, { /** 命令正则匹配 */ - reg: toggleMode === 'at' ? '^[^#][sS]*' : '^#chat[^gpt][sS]*', + reg: toggleMode === 'at' ? '^[^#][sS]*' : '^#(图片)?chat[^gpt][sS]*', /** 执行方法 */ fnc: 'chatgpt', log: false @@ -483,6 +483,7 @@ export class chatgpt extends plugin { async chatgpt (e) { let msg = e.msg let prompt + let forcePictureMode = false if (this.toggleMode === 'at') { if (!msg || e.msg?.startsWith('#')) { return false @@ -533,7 +534,10 @@ export class chatgpt extends plugin { } return false } - prompt = _.replace(e.msg.trimStart(), '#chat', '').trim() + if (e.msg.trimStart().startsWith('#图片chat')) { + forcePictureMode = true + } + prompt = _.replace(e.msg.trimStart(), /#(图片)?chat/, '').trim() if (prompt.length === 0) { return false } @@ -548,10 +552,10 @@ export class chatgpt extends plugin { const use = (userData.mode === 'default' ? null : userData.mode) || await redis.get('CHATGPT:USE') || 'api' // 自动化插件本月已发送xx条消息更新太快,由于延迟和缓存问题导致不同客户端不一样,at文本和获取的card不一致。因此单独处理一下 prompt = prompt.replace(/^|本月已发送\d+条消息/, '') - await this.abstractChat(e, prompt, use) + await this.abstractChat(e, prompt, use, forcePictureMode) } - async abstractChat (e, prompt, use) { + async abstractChat (e, prompt, use, forcePictureMode = false) { // 关闭私聊通道后不回复 if (!e.isMaster && e.isPrivate && !Config.enablePrivateChat) { return false @@ -981,7 +985,7 @@ export class chatgpt extends plugin { } else { await this.reply('合成语音发生错误~') } - } else if (userSetting.usePicture || (!Config.enableMd && Config.autoUsePicture && response.length > Config.autoUsePictureThreshold)) { + } else if (forcePictureMode || userSetting.usePicture || (Config.autoUsePicture && response.length > Config.autoUsePictureThreshold)) { try { await this.renderImage(e, use, response, prompt, quotemessage, mood, chatMessage.suggestedResponses, imgUrls) } catch (err) { @@ -1052,11 +1056,11 @@ export class chatgpt extends plugin { } async chatgpt1 (e) { - return await this.otherMode(e, 'api', '#chat1') + return await this.otherMode(e, 'api', /#(图片)?chat1/) } async chatgpt3 (e) { - return await this.otherMode(e, 'api3', '#chat3') + return await this.otherMode(e, 'api3', /#(图片)?chat3/) } async chatglm (e) { @@ -1064,31 +1068,31 @@ export class chatgpt extends plugin { } async bing (e) { - return await this.otherMode(e, 'bing') + return await this.otherMode(e, 'bing', /#(图片)?bing/) } async claude2 (e) { - return await this.otherMode(e, 'claude2', /^#claude(2|3|.ai)/) + return await this.otherMode(e, 'claude2', /^#(图片)?claude(2|3|.ai)/) } async claude (e) { - return await this.otherMode(e, 'claude') + return await this.otherMode(e, 'claude', /#(图片)?claude/) } async qwen (e) { - return await this.otherMode(e, 'qwen') + return await this.otherMode(e, 'qwen', /#(图片)?qwen/) } async glm4 (e) { - return await this.otherMode(e, 'chatglm4', '#glm4') + return await this.otherMode(e, 'chatglm4', /#(图片)?glm4/) } async gemini (e) { - return await this.otherMode(e, 'gemini') + return await this.otherMode(e, 'gemini', /#(图片)?gemini/) } async xh (e) { - return await this.otherMode(e, 'xh') + return await this.otherMode(e, 'xh', /#(图片)?xh/) } async cacheContent (e, use, content, prompt, quote = [], mood = '', suggest = '', imgUrls = []) { @@ -1396,7 +1400,8 @@ export class chatgpt extends plugin { if (prompt.length === 0) { return false } - await this.abstractChat(e, prompt, mode) + let forcePictureMode = e.msg.trimStart().startsWith('#图片') + await this.abstractChat(e, prompt, mode, forcePictureMode) return true } } diff --git a/client/OpenAILikeClient.js b/client/OpenAILikeClient.js deleted file mode 100644 index e69de29b..00000000 diff --git a/guoba.support.js b/guoba.support.js index 03403152..8dec6fb7 100644 --- a/guoba.support.js +++ b/guoba.support.js @@ -63,12 +63,12 @@ export function supportGuoba () { bottomHelpMessage: '独立的后台管理面板(默认3321端口),与锅巴类似。工具箱会有额外占用,启动速度稍慢,酌情开启。修改后需重启生效!!!', component: 'Switch' }, - { - field: 'enableMd', - label: 'QQ开启markdown', - bottomHelpMessage: 'qq的第三方md,非QQBot。需要适配器实现segment.markdown和segment.button方可使用,否则不建议开启,会造成各种错误。默认关闭', - component: 'Switch' - }, + // { + // field: 'enableMd', + // label: 'QQ开启markdown', + // bottomHelpMessage: 'qq的第三方md,非QQBot。需要适配器实现segment.markdown和segment.button方可使用,否则不建议开启,会造成各种错误。默认关闭', + // component: 'Switch' + // }, { field: 'translateSource', label: '翻译来源', From d08e9e410253c6c6753a9148c01cac73f74f9510 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Fri, 11 Oct 2024 22:28:14 +0800 Subject: [PATCH 6/9] =?UTF-8?q?feat:=20=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=90=8E=E5=A4=84=E7=90=86=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/chat.js | 9 +++++++++ apps/{ => post}/button.js | 4 ++-- apps/post/example_handler.js | 26 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) rename apps/{ => post}/button.js (99%) create mode 100644 apps/post/example_handler.js diff --git a/apps/chat.js b/apps/chat.js index 2f934bef..e8a1e58f 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -823,6 +823,15 @@ export class chatgpt extends plugin { } } let response = chatMessage?.text?.replace('\n\n\n', '\n') + if (handler.has('chatgpt.response.post')) { + handler.call('chatgpt.response.post', this.e, { + content: response, + use, + prompt + }, true).catch(err => { + logger.error('后处理器出错', err) + }) + } let mood = 'blandness' if (!response) { await this.reply('没有任何回复', true) diff --git a/apps/button.js b/apps/post/button.js similarity index 99% rename from apps/button.js rename to apps/post/button.js index d443ba4b..8e4f4770 100644 --- a/apps/button.js +++ b/apps/post/button.js @@ -1,5 +1,5 @@ -import plugin from '../../../lib/plugins/plugin.js' -import { Config } from '../utils/config.js' +import plugin from '../../../../lib/plugins/plugin.js' +import { Config } from '../../utils/config.js' const PLUGIN_CHAT = 'ChatGpt 对话' const PLUGIN_MANAGEMENT = 'ChatGPT-Plugin 管理' diff --git a/apps/post/example_handler.js b/apps/post/example_handler.js new file mode 100644 index 00000000..b0004735 --- /dev/null +++ b/apps/post/example_handler.js @@ -0,0 +1,26 @@ +import plugin from '../../../../lib/plugins/plugin.js' + +/** + * 示例后处理器。你可以在example下面写一个新的。默认会调用所有此key的处理器 + */ +export class ChatGPTResponsePostHandler extends plugin { + constructor () { + super({ + name: 'chatgpt文本回复后处理器', + priority: 999999, + namespace: 'chatgpt-plugin', + handler: [{ + key: 'chatgpt.response.post', // key必须是chatgpt.response.post + fn: 'postHandler' + }] + }) + } + + async postHandler (e, options, reject) { + const { content, use, prompt } = options + // 你可以在这里处理返回的文本,比如使用自定义的语音api来合成语音 + // const audio = customTTS(content) + // e.reply(segment.audio(audio)) + // 返回值会被忽略 + } +} From 479028584ef447ee40804a5cae0af2669795e3bd Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Fri, 11 Oct 2024 23:04:54 +0800 Subject: [PATCH 7/9] fix: move files --- apps/{post => }/button.js | 4 +-- apps/chat.js | 2 ++ apps/example_handler.js | 48 ++++++++++++++++++++++++++++++++++++ apps/post/example_handler.js | 26 ------------------- 4 files changed, 52 insertions(+), 28 deletions(-) rename apps/{post => }/button.js (99%) create mode 100644 apps/example_handler.js delete mode 100644 apps/post/example_handler.js diff --git a/apps/post/button.js b/apps/button.js similarity index 99% rename from apps/post/button.js rename to apps/button.js index 8e4f4770..d443ba4b 100644 --- a/apps/post/button.js +++ b/apps/button.js @@ -1,5 +1,5 @@ -import plugin from '../../../../lib/plugins/plugin.js' -import { Config } from '../../utils/config.js' +import plugin from '../../../lib/plugins/plugin.js' +import { Config } from '../utils/config.js' const PLUGIN_CHAT = 'ChatGpt 对话' const PLUGIN_MANAGEMENT = 'ChatGPT-Plugin 管理' diff --git a/apps/chat.js b/apps/chat.js index e8a1e58f..a7fa756b 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -823,7 +823,9 @@ export class chatgpt extends plugin { } } let response = chatMessage?.text?.replace('\n\n\n', '\n') + if (handler.has('chatgpt.response.post')) { + logger.debug('调用后处理器: chatgpt.response.post') handler.call('chatgpt.response.post', this.e, { content: response, use, diff --git a/apps/example_handler.js b/apps/example_handler.js new file mode 100644 index 00000000..205f9338 --- /dev/null +++ b/apps/example_handler.js @@ -0,0 +1,48 @@ + +/** + * 示例后处理器。你可以在example下面写一个新的。默认会调用所有此key的处理器 + */ +export class ChatGPTResponsePostHandler extends plugin { + constructor () { + super({ + name: 'chatgpt文本回复后处理器', + priority: -100, + namespace: 'chatgpt-plugin', + handler: [{ + key: 'chatgpt.response.post', // key必须是chatgpt.response.post + fn: 'postHandler' + }] + }) + } + + async postHandler (e, options, reject) { + const { content, use, prompt } = options + // 你可以在这里处理返回的文本,比如使用自定义的语音api来合成语音 + // const audio = customTTS(content) + // e.reply(segment.record(audio)) + // 返回值会被忽略 + const response = await fetch('https://api.fish.audio/v1/tts', { + method: 'POST', + headers: { + Authorization: 'Bearer 5e614bcc80a34789837fdb0f1269b2c4', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + text: content, + reference_id: '1aacaeb1b840436391b835fd5513f4c4', + format: 'mp3', + latency: 'normal' + }) + }) + + if (!response.ok) { + throw new Error(`无法从服务器获取音频数据:${response.statusText}`) + } + + const audio = await response.blob() + // to Buffer + const buffer = await audio.arrayBuffer() + e.reply(segment.record(Buffer.from(buffer))) + // e.reply(segment.record(audio)) + } +} diff --git a/apps/post/example_handler.js b/apps/post/example_handler.js deleted file mode 100644 index b0004735..00000000 --- a/apps/post/example_handler.js +++ /dev/null @@ -1,26 +0,0 @@ -import plugin from '../../../../lib/plugins/plugin.js' - -/** - * 示例后处理器。你可以在example下面写一个新的。默认会调用所有此key的处理器 - */ -export class ChatGPTResponsePostHandler extends plugin { - constructor () { - super({ - name: 'chatgpt文本回复后处理器', - priority: 999999, - namespace: 'chatgpt-plugin', - handler: [{ - key: 'chatgpt.response.post', // key必须是chatgpt.response.post - fn: 'postHandler' - }] - }) - } - - async postHandler (e, options, reject) { - const { content, use, prompt } = options - // 你可以在这里处理返回的文本,比如使用自定义的语音api来合成语音 - // const audio = customTTS(content) - // e.reply(segment.audio(audio)) - // 返回值会被忽略 - } -} From aa2ac7b5d3b5ff33646166a44ff825a5ab73ea67 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Fri, 11 Oct 2024 23:07:09 +0800 Subject: [PATCH 8/9] fix: add example --- apps/example_handler.js | 50 ++++++++++++++++++-------------------- client/OpenAILikeClient.js | 29 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 client/OpenAILikeClient.js diff --git a/apps/example_handler.js b/apps/example_handler.js index 205f9338..27f60c56 100644 --- a/apps/example_handler.js +++ b/apps/example_handler.js @@ -1,4 +1,3 @@ - /** * 示例后处理器。你可以在example下面写一个新的。默认会调用所有此key的处理器 */ @@ -18,31 +17,30 @@ export class ChatGPTResponsePostHandler extends plugin { async postHandler (e, options, reject) { const { content, use, prompt } = options // 你可以在这里处理返回的文本,比如使用自定义的语音api来合成语音 - // const audio = customTTS(content) - // e.reply(segment.record(audio)) - // 返回值会被忽略 - const response = await fetch('https://api.fish.audio/v1/tts', { - method: 'POST', - headers: { - Authorization: 'Bearer 5e614bcc80a34789837fdb0f1269b2c4', - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - text: content, - reference_id: '1aacaeb1b840436391b835fd5513f4c4', - format: 'mp3', - latency: 'normal' - }) - }) - if (!response.ok) { - throw new Error(`无法从服务器获取音频数据:${response.statusText}`) - } - - const audio = await response.blob() - // to Buffer - const buffer = await audio.arrayBuffer() - e.reply(segment.record(Buffer.from(buffer))) - // e.reply(segment.record(audio)) + // 返回值会被忽略 + // 以下是一个简单的例子 + // const response = await fetch('https://api.fish.audio/v1/tts', { + // method: 'POST', + // headers: { + // Authorization: 'Bearer + key', + // 'Content-Type': 'application/json' + // }, + // body: JSON.stringify({ + // text: content, + // reference_id: '1aacaeb1b840436391b835fd5513f4c4', + // format: 'mp3', + // latency: 'normal' + // }) + // }) + // + // if (!response.ok) { + // throw new Error(`无法从服务器获取音频数据:${response.statusText}`) + // } + // + // const audio = await response.blob() + // // to Buffer + // const buffer = await audio.arrayBuffer() + // e.reply(segment.record(Buffer.from(buffer))) } } diff --git a/client/OpenAILikeClient.js b/client/OpenAILikeClient.js new file mode 100644 index 00000000..33a37187 --- /dev/null +++ b/client/OpenAILikeClient.js @@ -0,0 +1,29 @@ +import { BaseClient } from './BaseClient.js' + +export class OpenAILikeClient extends BaseClient { + constructor (props) { + super(props) + this.model = props.model + this.key = props.key + this.baseUrl = props.baseUrl + this.debug = props.debug + } + + async sendMessageRaw (text, opt = {}) { + const messages = await this.getHistory(opt.parentMessageId, opt.conversationId) + const response = await fetch(this.baseUrl, { + method: 'POST', + headers: { + 'Content-Type': 'application-json', + Authorization: `Bearer ${this.key}` + }, + body: JSON.stringify({ + model: this.model, + messages, + stream: false, + ...opt.completionParams || {} + }) + }) + return await response.json() + } +} From 2b9734c64138c38e7eb94f8cf2713871529d7665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=92=E9=9D=92?= <126029323+Jin1c-3@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:01:55 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E5=85=BC=E5=AE=B9trss=20(#723)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jin1c on imini --- apps/update.js | 7 ++++--- model/core.js | 2 +- utils/tools/QueryUserinfoTool.js | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/update.js b/apps/update.js index f22c8a6d..2effe56b 100644 --- a/apps/update.js +++ b/apps/update.js @@ -186,13 +186,14 @@ export class Update extends plugin { * @returns */ async makeForwardMsg (title, msg, end) { - let nickname = (this.e.bot ?? Bot).nickname + const _bot = this.e.bot ?? Bot + let nickname = _bot.nickname if (this.e.isGroup) { - let info = await (this.e.bot ?? Bot).getGroupMemberInfo(this.e.group_id, (this.e.bot ?? Bot).uin) + let info = await _bot?.pickMember?.(this.e.group_id, _bot.uin) || await _bot?.getGroupMemberInfo?.(this.e.group_id, _bot.uin) nickname = info.card || info.nickname } let userInfo = { - user_id: (this.e.bot ?? Bot).uin, + user_id: _bot.uin, nickname } diff --git a/model/core.js b/model/core.js index 7d1b9979..78de7952 100644 --- a/model/core.js +++ b/model/core.js @@ -1058,7 +1058,7 @@ async function collectTools (e) { } let systemAddition = '' if (e.isGroup) { - let botInfo = await e.bot.getGroupMemberInfo(e.group_id, getUin(e), true) + let botInfo = await e.bot?.pickMember?.(e.group_id, getUin(e), true) || await e.bot?.getGroupMemberInfo?.(e.group_id, getUin(e), true) if (botInfo.role !== 'member') { // 管理员才给这些工具 tools.push(...[new EditCardTool(), new JinyanTool(), new KickOutTool(), new HandleMessageMsgTool(), new SetTitleTool()]) diff --git a/utils/tools/QueryUserinfoTool.js b/utils/tools/QueryUserinfoTool.js index 974c08b0..2a0d422f 100644 --- a/utils/tools/QueryUserinfoTool.js +++ b/utils/tools/QueryUserinfoTool.js @@ -18,8 +18,8 @@ export class QueryUserinfoTool extends AbstractTool { try { let { qq } = opts qq = isNaN(qq) || !qq ? e.sender.user_id : parseInt(qq.trim()) - if (e.isGroup && typeof e.bot.getGroupMemberInfo === 'function') { - let user = await e.bot.getGroupMemberInfo(e.group_id, qq || e.sender.user_id, true) + if (e.isGroup) { + let user = await e.bot?.pickMember?.(e.group_id, qq || e.sender.user_id, true) || await e.bot?.getGroupMemberInfo?.(e.group_id, qq || e.sender.user_id, true) // let mm = await e.group.getMemberMap() // let user = mm.get(qq) || e.sender.user_id let master = (await getMasterQQ())[0]