mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
一些功能补正和增强 (#217)
* 修复引用转发,默认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的情况下渲染错误 * 改为使用base64传递返回数据 * 当异常过多时使用图片输出 * 添加锅巴面板配置支持 * 补充遗漏的默认配置 * 修复qr模式下引用未被传递的问题 * 修复未将引用数据传输给缓存服务器的问题 * 删除无用的bingTimeoutMs配置项 * 添加消息队列超时弹出 * 优化图片模式处理,解决对话队列卡住的问题 * 添加对图片ocr的支持 * 添加图片识别配置项 * 添加黑名单配置项 * 修复一些bug * 修改锅巴配置格式和描述 * 传入数据也使用markdown * 图片识别换行改为marked兼容 * 添加绘图CD配置项 * 独立render模块,添加图片回复引用 * 添加必应风格 * 修复上下文,修改bing样式 * 修复上下文 * 添加Sydney上下文支持 * 调整不同模式下的bing渲染颜色 * 修复样式 * 修复无法结束会话的问题 * fix: 更新版本号 * 修复无法结束对话的问题 * 向缓存服务器传送样式 * 为网址格式的配置添加验证 * 去除重复的Keyv删除,取消锅巴配置格式检查 * 闭合中断的代码块 * 试添加Sydney图片模式的情感显示 * 修复at不兼容 * 处理意外的markdown包裹和结构解析修复 * 修复markdown处理的顺序错误 * 兼容json换行 --------- Co-authored-by: ikechan8370 <geyinchibuaa@gmail.com>
This commit is contained in:
parent
cc785261eb
commit
f21c3bee39
14 changed files with 183 additions and 4 deletions
37
apps/chat.js
37
apps/chat.js
|
|
@ -12,6 +12,7 @@ import {
|
|||
makeForwardMsg,
|
||||
upsertMessage,
|
||||
randomString,
|
||||
completeJSON,
|
||||
getDefaultUserSetting, isCN, getMasterQQ
|
||||
} from '../utils/common.js'
|
||||
import { ChatGPTPuppeteer } from '../utils/browser.js'
|
||||
|
|
@ -743,16 +744,45 @@ export class chatgpt extends plugin {
|
|||
await redis.set(key, JSON.stringify(previousConversation), Config.conversationPreserveTime > 0 ? { EX: Config.conversationPreserveTime } : {})
|
||||
}
|
||||
let response = chatMessage?.text
|
||||
let mood = 'blandness'
|
||||
if (!response) {
|
||||
await e.reply('没有任何回复', true)
|
||||
return
|
||||
}
|
||||
// 分离内容和情绪
|
||||
if (Config.sydneyMood) {
|
||||
let temp_response = {}
|
||||
try {
|
||||
temp_response = JSON.parse(response)
|
||||
} catch (error) {
|
||||
// 尝试还原json格式
|
||||
try {
|
||||
temp_response = completeJSON(response)
|
||||
temp_response = JSON.parse(temp_response)
|
||||
} catch (error) {
|
||||
logger.error('数据格式错误',error)
|
||||
}
|
||||
}
|
||||
if (temp_response.text) response = temp_response.text
|
||||
if (temp_response.mood) mood = temp_response.mood
|
||||
} else {
|
||||
mood = ''
|
||||
}
|
||||
// 检索是否有屏蔽词
|
||||
const blockWord = Config.blockWords.find(word => response.toLowerCase().includes(word.toLowerCase()))
|
||||
if (blockWord) {
|
||||
await this.reply('返回内容存在敏感词,我不想回答你', true)
|
||||
return false
|
||||
}
|
||||
//处理中断的代码区域
|
||||
const codeBlockCount = (response.match(/```/g) || []).length;
|
||||
const shouldAddClosingBlock = codeBlockCount % 2 === 1 && !response.endsWith('```');
|
||||
if (shouldAddClosingBlock) {
|
||||
response += '\n```';
|
||||
}
|
||||
if (codeBlockCount && !shouldAddClosingBlock) {
|
||||
response = response.replace(/```$/, '\n```');
|
||||
}
|
||||
|
||||
let quotemessage = []
|
||||
if (chatMessage?.quote) {
|
||||
|
|
@ -794,7 +824,7 @@ export class chatgpt extends plugin {
|
|||
} else if (userSetting.usePicture || (Config.autoUsePicture && response.length > Config.autoUsePictureThreshold)) {
|
||||
// todo use next api of chatgpt to complete incomplete respoonse
|
||||
try {
|
||||
await this.renderImage(e, use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', response, prompt, quotemessage, Config.showQRCode)
|
||||
await this.renderImage(e, use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index', response, prompt, quotemessage, mood, Config.showQRCode)
|
||||
} catch (err) {
|
||||
logger.warn('error happened while uploading content to the cache server. QR Code will not be showed in this picture.')
|
||||
logger.error(err)
|
||||
|
|
@ -912,7 +942,7 @@ export class chatgpt extends plugin {
|
|||
return true
|
||||
}
|
||||
|
||||
async renderImage (e, template, content, prompt, quote = [], cache = false) {
|
||||
async renderImage (e, template, content, prompt, quote = [], mood = '', cache = false) {
|
||||
let cacheData = { file: '', cacheUrl: Config.cacheUrl }
|
||||
if (cache) {
|
||||
if (Config.cacheEntry) cacheData.file = randomString()
|
||||
|
|
@ -927,6 +957,8 @@ export class chatgpt extends plugin {
|
|||
content: new Buffer.from(content).toString('base64'),
|
||||
prompt: new Buffer.from(prompt).toString('base64'),
|
||||
senderName: e.sender.nickname,
|
||||
style: Config.toneStyle,
|
||||
mood: mood,
|
||||
quote
|
||||
},
|
||||
bing: use === 'bing',
|
||||
|
|
@ -950,6 +982,7 @@ export class chatgpt extends plugin {
|
|||
quotes: quote,
|
||||
cache: cacheData,
|
||||
style: Config.toneStyle,
|
||||
mood: mood,
|
||||
version
|
||||
}, { retType: Config.quoteReply ? 'base64' : '' }), e.isGroup && Config.quoteReply)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue