From 59d5e904b5ab76ebc7bc37ca325913a9af5d0987 Mon Sep 17 00:00:00 2001 From: HalcyonAlcedo <41666148+HalcyonAlcedo@users.noreply.github.com> Date: Mon, 20 Feb 2023 18:32:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug=20(#175)?= 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 * 防止script攻击 * 修复网页模板错误 * 修复bing页面引用错误 * 缓存服务器异常时处理 * 添加默认配置加载 * 修复配置文件路径错误 * 删除重复的模板文件,修复二维码地址错误 * 修正图片渲染错误 * 修复引用渲染错误 * 二维码网址统一改为使用本地配置 * 添加关闭思考提示的配置项 * 修复在Windows上无法载入配置文件的问题 * 修复关闭qr的情况下渲染错误 --------- Co-authored-by: ikechan8370 --- .gitignore | 2 +- apps/chat.js | 18 +++++++++--------- config/config.example.js | 2 ++ utils/config.js | 5 +++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 5260dca..0ad42c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ config/* !config/config.example.js -node_modules/ \ No newline at end of file +node_modules/ diff --git a/apps/chat.js b/apps/chat.js index 9fb65a4..ef0b2ca 100644 --- a/apps/chat.js +++ b/apps/chat.js @@ -288,7 +288,7 @@ export class chatgpt extends plugin { // 队列队尾插入,开始排队 await redis.rPush('CHATGPT:CHAT_QUEUE', [randomId]) let confirm = await redis.get('CHATGPT:CONFIRM') - let confirmOn = !confirm || confirm === 'on' + let confirmOn = (!confirm || confirm === 'on') && Config.thinkingTips if (await redis.lIndex('CHATGPT:CHAT_QUEUE', 0) === randomId) { if (confirmOn) { await this.reply('我正在思考如何回复你,请稍等', true, { recallMsg: 8 }) @@ -468,12 +468,12 @@ export class chatgpt extends plugin { } ) let cache = {file:'',cacheUrl:Config.cacheUrl} - if (cacheres.ok) - cache = await cacheres.json() - cache.cacheUrl = Config.cacheUrl + if (cacheres.ok) { + cache = Object.assign({}, cache, await cacheres.json()) + } await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: escapeHtml(response), prompt: escapeHtml(prompt), senderName: e.sender.nickname, cache: cache }) } else { - await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: escapeHtml(response), prompt: escapeHtml(prompt), senderName: e.sender.nickname }) + await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: escapeHtml(response), prompt: escapeHtml(prompt), senderName: e.sender.nickname, cache: {file:'',cacheUrl:Config.cacheUrl} }) } } else { let quotemessage = [] @@ -504,12 +504,12 @@ export class chatgpt extends plugin { } ) let cache = {file:'',cacheUrl:Config.cacheUrl} - if (cacheres.ok) - cache = await cacheres.json() - cache.cacheUrl = Config.cacheUrl + if (cacheres.ok) { + cache = Object.assign({}, cache, await cacheres.json()) + } await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: escapeHtml(response), prompt: escapeHtml(prompt), senderName: e.sender.nickname, quote: quotemessage.length > 0 , quotes: quotemessage, cache: cache }) } else { - await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: escapeHtml(response), prompt: escapeHtml(prompt), senderName: e.sender.nickname, quote: quotemessage.length > 0 , quotes: quotemessage }) + await e.runtime.render('chatgpt-plugin', use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', { content: escapeHtml(response), prompt: escapeHtml(prompt), senderName: e.sender.nickname, quote: quotemessage.length > 0 , quotes: quotemessage, cache: {file:'',cacheUrl:Config.cacheUrl} }) } } else { await this.reply(`${response}`, e.isGroup) diff --git a/config/config.example.js b/config/config.example.js index def12d6..e2aa313 100644 --- a/config/config.example.js +++ b/config/config.example.js @@ -57,6 +57,8 @@ export default { // promptPrefixOverride: 'Your answer shouldn\'t be too verbose. If you are generating a list, do not have too many items. Keep the number of items short. Prefer to answer in Chinese.', // AI认为的自己的名字,当你问他你是谁是他会回答这里的名字。 // assistantLabel: 'ChatGPT', + // 是否开启AI正在思考中的提示信息 + // thinkingTips: true, // *********************************************************************************************************************************** // 以下为浏览器方式的配置 * // *********************************************************************************************************************************** diff --git a/utils/config.js b/utils/config.js index 9d9abc8..0cda75e 100644 --- a/utils/config.js +++ b/utils/config.js @@ -16,6 +16,7 @@ const defaultConfig = { reverseProxy: 'https://chatgpt.pawan.krd/api/completions', promptPrefixOverride: 'Your answer shouldn\'t be too verbose. If you are generating a list, do not have too many items. Keep the number of items short. Prefer to answer in Chinese.', assistantLabel: 'ChatGPT', + thinkingTips: true, username: '', password: '', headless: false, @@ -30,11 +31,11 @@ const _path = process.cwd() let config = {} if (fs.existsSync(`${_path}/plugins/chatgpt-plugin/config/config.js`)) { const fullPath = fs.realpathSync(`${_path}/plugins/chatgpt-plugin/config/config.js`); - config = (await import(fullPath)).default; + config = (await import(`file://${fullPath}`)).default; } else if (fs.existsSync(`${_path}/plugins/chatgpt-plugin/config/index.js`)) { // 兼容旧版本 const fullPath = fs.realpathSync(`${_path}/plugins/chatgpt-plugin/config/index.js`); - config = (await import(fullPath)).Config; + config = (await import(`file://${fullPath}`)).Config; } export const Config = Object.assign({}, defaultConfig, config); \ No newline at end of file