From f1479f0e104605d753ee1064aef19eda475ac379 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Sun, 26 Mar 2023 21:43:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AF=95=E5=9B=BE=E6=8B=AF=E6=95=91?= =?UTF-8?q?=E6=B5=8F=E8=A7=88=E5=99=A8=E6=A8=A1=E5=BC=8F=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E8=A1=8C=E5=B0=B1=E5=BC=83=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/chat.js | 26 ++++++++++++++++--- utils/browser.js | 65 +----------------------------------------------- 2 files changed, 24 insertions(+), 67 deletions(-) diff --git a/apps/chat.js b/apps/chat.js index c7afc94..ebb10f9 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -256,6 +256,14 @@ export class chatgpt extends plugin { await redis.del(`CHATGPT:CONVERSATIONS_BING:${e.sender.user_id}`) await this.reply('已结束当前对话,请@我进行聊天以开启新的对话', true) } + } else if (use === 'browser') { + let c = await redis.get(`CHATGPT:CONVERSATIONS_BROWSER:${e.sender.user_id}`) + if (!c) { + await this.reply('当前没有开启对话', true) + } else { + await redis.del(`CHATGPT:CONVERSATIONS_BROWSER:${e.sender.user_id}`) + await this.reply('已结束当前对话,请@我进行聊天以开启新的对话', true) + } } } else { let at = ats[0] @@ -309,6 +317,14 @@ export class chatgpt extends plugin { await redis.del(`CHATGPT:CONVERSATIONS_BING:${qq}`) await this.reply(`已结束${atUser}的对话,TA仍可以@我进行聊天以开启新的对话`, true) } + } else if (use === 'browser') { + let c = await redis.get(`CHATGPT:CONVERSATIONS_BROWSER:${qq}`) + if (!c) { + await this.reply(`当前${atUser}没有开启对话`, true) + } else { + await redis.del(`CHATGPT:CONVERSATIONS_BROWSER:${qq}`) + await this.reply(`已结束${atUser}的对话,TA仍可以@我进行聊天以开启新的对话`, true) + } } } } @@ -674,6 +690,10 @@ export class chatgpt extends plugin { key = `CHATGPT:CONVERSATIONS_CHATGLM:${e.sender.user_id}` break } + case 'browser': { + key = `CHATGPT:CONVERSATIONS_BROWSER:${e.sender.user_id}` + break + } } let ctime = new Date() previousConversation = await redis.get(key) || JSON.stringify({ @@ -745,15 +765,15 @@ export class chatgpt extends plugin { } if (useTTS) { if (Config.ttsSpace && response.length <= Config.ttsAutoFallbackThreshold) { - let audio_err = false + let audioErr = false try { let wav = await generateAudio(response, speaker, '中日混合(中文用[ZH][ZH]包裹起来,日文用[JA][JA]包裹起来)') await e.reply(segment.record(wav)) } catch (err) { await this.reply('合成语音发生错误,我用文本回复你吧') - audio_err = true + audioErr = true } - if (Config.alsoSendText || audio_err) { + if (Config.alsoSendText || audioErr) { await this.reply(`${response}`, e.isGroup) if (quotemessage.length > 0) { this.reply(await makeForwardMsg(this.e, quotemessage)) diff --git a/utils/browser.js b/utils/browser.js index 1ee181e..288341f 100644 --- a/utils/browser.js +++ b/utils/browser.js @@ -372,69 +372,6 @@ export class ChatGPTPuppeteer extends Puppeteer { } } - // async getLastMessage(): Promise { - // const messages = await this.getMessages() - - // if (messages) { - // return messages[messages.length - 1] - // } else { - // return null - // } - // } - - // async getPrompts(): Promise { - // // Get all prompts - // const messages = await this._page.$$( - // '.text-base:has(.whitespace-pre-wrap):not(:has(button:nth-child(2))) .whitespace-pre-wrap' - // ) - - // // Prompts are always plaintext - // return Promise.all(messages.map((a) => a.evaluate((el) => el.textContent))) - // } - - // async getMessages(): Promise { - // // Get all complete messages - // // (in-progress messages that are being streamed back don't contain action buttons) - // const messages = await this._page.$$( - // '.text-base:has(.whitespace-pre-wrap):has(button:nth-child(2)) .whitespace-pre-wrap' - // ) - - // if (this._markdown) { - // const htmlMessages = await Promise.all( - // messages.map((a) => a.evaluate((el) => el.innerHTML)) - // ) - - // const markdownMessages = htmlMessages.map((messageHtml) => { - // // parse markdown from message HTML - // messageHtml = messageHtml - // .replaceAll('Copy code', '') - // .replace(/Copy code\s*<\/button>/gim, '') - - // return html2md(messageHtml, { - // ignoreTags: [ - // 'button', - // 'svg', - // 'style', - // 'form', - // 'noscript', - // 'script', - // 'meta', - // 'head' - // ], - // skipTags: ['button', 'svg'] - // }) - // }) - - // return markdownMessages - // } else { - // // plaintext - // const plaintextMessages = await Promise.all( - // messages.map((a) => a.evaluate((el) => el.textContent)) - // ) - // return plaintextMessages - // } - // } - async sendMessage ( message, opts = {} @@ -496,7 +433,7 @@ export class ChatGPTPuppeteer extends Puppeteer { } } ], - model: Config.plus ? 'text-davinci-002-render-sha' : 'text-davinci-002-render-sha', + model: Config.plus ? Config.useGPT4 ? 'gpt-4' : 'text-davinci-002-render-sha' : 'text-davinci-002-render-sha', parent_message_id: parentMessageId }