From a4f12eaf09fe306f4ef8ab023a3b63cced3ead13 Mon Sep 17 00:00:00 2001 From: HalcyonAlcedo <41666148+HalcyonAlcedo@users.noreply.github.com> Date: Sun, 19 Feb 2023 00:17:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E5=9B=BE=E7=89=87=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=A4=96=E9=83=A8=E9=A1=B5=E9=9D=A2=E4=BF=9D=E5=AD=98=20(#167)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复引用转发,默认bing模式并发 * 开启stream增加稳定性 * fix: remove queue element only in non-bing mode * 使用chatgpt-api自带的超时逻辑,文字过多时启动切换到图片输出防止被吞 * Update chat.js * 添加Bing专用的图片输出样式 * 添加chatgpt的新图片模式,临时处理切换api导致的对话异常 * 修改bing样式表 * 为图片添加外部页面缓存 * 为图片模式添加MathJax * feat: add switch for qrcode --------- Co-authored-by: ikechan8370 --- apps/chat.js | 46 ++++++++++++++++++- config/index.js | 2 + resources/content/Bing/index.html | 17 ++++++- .../Bing/static/js/jquery.qrcode.min.js | 28 +++++++++++ .../content/Bing/static/js/tex-mml-chtml.js | 1 + resources/content/ChatGPT/index.html | 16 +++++-- .../ChatGPT/static/js/jquery.qrcode.min.js | 28 +++++++++++ .../ChatGPT/static/js/tex-mml-chtml.js | 1 + 8 files changed, 132 insertions(+), 7 deletions(-) create mode 100644 resources/content/Bing/static/js/jquery.qrcode.min.js create mode 100644 resources/content/Bing/static/js/tex-mml-chtml.js create mode 100644 resources/content/ChatGPT/static/js/jquery.qrcode.min.js create mode 100644 resources/content/ChatGPT/static/js/tex-mml-chtml.js diff --git a/apps/chat.js b/apps/chat.js index 7dc35da..5ae128b 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -442,7 +442,28 @@ export class chatgpt extends plugin { let converted = response // converter.makeHtml(response) /** 最后回复消息 */ - await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: converted, prompt, senderName: e.sender.nickname }) + if (Config.showQRCode) { + let cacheres = await fetch('http://content.alcedogroup.com/cache', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + content: { + content: converted, + prompt, + senderName: e.sender.nickname + // quote: quotemessage + }, + bing: use === 'bing' + }) + } + ) + let cache = await cacheres.json() + await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: converted, prompt, senderName: e.sender.nickname, cache: cache.file }) + } else { + await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: converted, prompt, senderName: e.sender.nickname }) + } } else { let quotemessage = [] if (chatMessage?.quote) { @@ -454,7 +475,28 @@ export class chatgpt extends plugin { } if (Config.autoUsePicture && response.length > Config.autoUsePictureThreshold) { // 文字过多时自动切换到图片模式输出 - await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: response, prompt, quote: quotemessage, senderName: e.sender.nickname }) + if (Config.showQRCode) { + let cacheres = await fetch('http://content.alcedogroup.com/cache', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + content: { + content: response, + prompt, + senderName: e.sender.nickname, + quote: quotemessage + }, + bing: use === 'bing' + }) + } + ) + let cache = await cacheres.json() + await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: converted, prompt, senderName: e.sender.nickname, cache: cache.file }) + } else { + await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: converted, prompt, senderName: e.sender.nickname }) + } } else { await this.reply(`${response}`, e.isGroup) if (quotemessage.length > 0) { diff --git a/config/index.js b/config/index.js index 7e8bebd..ee41b5c 100644 --- a/config/index.js +++ b/config/index.js @@ -18,6 +18,8 @@ export const Config = { conversationPreserveTime: 0, // 触发方式 可选值:at 或 prefix 。at模式下只有at机器人才会回复。prefix模式下不需要at,但需要添加前缀#chat toggleMode: 'at', + // 是否在图片模式中启用二维码。该对话内容将被发送至第三方服务器以进行渲染展示。改为false关闭该功能 + showQRCode: true, // *********************************************************************************************************************************** // 以下为API方式(默认)的配置 * // *********************************************************************************************************************************** diff --git a/resources/content/Bing/index.html b/resources/content/Bing/index.html index db1e82a..929b052 100644 --- a/resources/content/Bing/index.html +++ b/resources/content/Bing/index.html @@ -18,7 +18,7 @@
@@ -31,6 +31,9 @@

New Bing

+ {{if cache != ''}} +

{{cache}}

+ {{/if}}
@@ -56,6 +59,7 @@
+ {{if quote.length > 0}}
@@ -69,13 +73,19 @@
+ {{/if}} + {{if cache != ''}} +
+ {{/if}}