mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
修复一些bug,图片识别支持多个图片 (#194)
* 修复引用转发,默认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兼容 --------- Co-authored-by: ikechan8370 <geyinchibuaa@gmail.com>
This commit is contained in:
parent
b22a7a69d6
commit
ba027dc760
4 changed files with 49 additions and 27 deletions
24
apps/chat.js
24
apps/chat.js
|
|
@ -16,8 +16,10 @@ import { deleteConversation, getConversations, getLatestMessageIdByConversationI
|
|||
* 每个对话保留的时长。单个对话内ai是保留上下文的。超时后销毁对话,再次对话创建新的对话。
|
||||
* 单位:秒
|
||||
* @type {number}
|
||||
*
|
||||
* 这里使用动态数据获取,以便于锅巴动态更新数据
|
||||
*/
|
||||
const CONVERSATION_PRESERVE_TIME = Config.conversationPreserveTime
|
||||
// const CONVERSATION_PRESERVE_TIME = Config.conversationPreserveTime
|
||||
const defaultPropmtPrefix = 'You answer as concisely as possible for each response (e.g. don’t be verbose). It is very important that you answer as concisely as possible, so please remember this. If you are generating a list, do not have too many items. Keep the number of items short.'
|
||||
|
||||
export class chatgpt extends plugin {
|
||||
|
|
@ -288,14 +290,16 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
if (e.img) {
|
||||
try {
|
||||
const imgorc = await Bot.imageOcr(e.img[0])
|
||||
if (imgorc.language === 'zh' || imgorc.language === 'en') {
|
||||
let imgtext = ''
|
||||
for (let text of imgorc.wordslist) {
|
||||
imgtext += `${text.words}\n`
|
||||
let imgOcrText = ''
|
||||
for (let i in e.img) {
|
||||
const imgorc = await Bot.imageOcr(e.img[i])
|
||||
if (imgorc.language === 'zh' || imgorc.language === 'en') {
|
||||
for (let text of imgorc.wordslist) {
|
||||
imgOcrText += `${text.words} \n`
|
||||
}
|
||||
}
|
||||
prompt = imgtext + prompt
|
||||
}
|
||||
prompt = imgOcrText + prompt
|
||||
} catch (err) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -429,7 +433,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
console.log(chatMessage)
|
||||
previousConversation.num = previousConversation.num + 1
|
||||
await redis.set(`CHATGPT:CONVERSATIONS:${e.sender.user_id}`, JSON.stringify(previousConversation), CONVERSATION_PRESERVE_TIME > 0 ? { EX: CONVERSATION_PRESERVE_TIME } : {})
|
||||
await redis.set(`CHATGPT:CONVERSATIONS:${e.sender.user_id}`, JSON.stringify(previousConversation), Config.conversationPreserveTime > 0 ? { EX: Config.conversationPreserveTime } : {})
|
||||
}
|
||||
let response = chatMessage?.text
|
||||
// 检索是否有屏蔽词
|
||||
|
|
@ -506,7 +510,7 @@ export class chatgpt extends plugin {
|
|||
body: JSON.stringify({
|
||||
content: {
|
||||
content: new Buffer.from(content).toString('base64'),
|
||||
prompt,
|
||||
prompt: new Buffer.from(prompt).toString('base64'),
|
||||
senderName: e.sender.nickname,
|
||||
quote
|
||||
},
|
||||
|
|
@ -525,7 +529,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
await e.runtime.render('chatgpt-plugin', template, {
|
||||
content: new Buffer.from(content).toString('base64'),
|
||||
prompt: escapeHtml(prompt),
|
||||
prompt: new Buffer.from(prompt).toString('base64'),
|
||||
senderName: e.sender.nickname,
|
||||
quote: quote.length > 0,
|
||||
quotes: quote,
|
||||
|
|
|
|||
|
|
@ -29,13 +29,13 @@ export function supportGuoba() {
|
|||
field: 'blockWords',
|
||||
label: '输出黑名单',
|
||||
bottomHelpMessage: '检查输出结果中是否有违禁词,如果存在黑名单中的违禁词则不输出',
|
||||
component: 'Input',
|
||||
component: 'InputTextArea',
|
||||
},
|
||||
{
|
||||
field: 'promptBlockWords',
|
||||
label: '输入黑名单',
|
||||
bottomHelpMessage: '检查输入结果中是否有违禁词,如果存在黑名单中的违禁词则不输出',
|
||||
component: 'Input',
|
||||
component: 'InputTextArea',
|
||||
},
|
||||
{
|
||||
field: 'imgOcr',
|
||||
|
|
@ -203,7 +203,7 @@ export function supportGuoba() {
|
|||
field: 'promptPrefixOverride',
|
||||
label: 'AI风格',
|
||||
bottomHelpMessage: '你可以在这里写入你希望AI回答的风格,比如希望优先回答中文,回答长一点等。',
|
||||
component: 'Input',
|
||||
component: 'InputTextArea',
|
||||
},
|
||||
{
|
||||
field: 'assistantLabel',
|
||||
|
|
@ -223,7 +223,7 @@ export function supportGuoba() {
|
|||
},
|
||||
{
|
||||
field: 'password',
|
||||
label: '用户名',
|
||||
label: '密码',
|
||||
bottomHelpMessage: 'OpenAI密码。',
|
||||
component: 'InputPassword',
|
||||
},
|
||||
|
|
@ -231,7 +231,7 @@ export function supportGuoba() {
|
|||
field: 'UA',
|
||||
label: '浏览器UA',
|
||||
bottomHelpMessage: '模拟浏览器UA,无特殊需求保持默认即可。',
|
||||
component: 'Input',
|
||||
component: 'InputTextArea',
|
||||
},
|
||||
{
|
||||
field: 'headless',
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@
|
|||
<h4>{{senderName}}</h4>
|
||||
</div>
|
||||
<div class="about-content">
|
||||
<h2>{{@ prompt}}</h2>
|
||||
<p class="markdown_prompt"></p>
|
||||
<span class="height-50"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -54,7 +54,7 @@
|
|||
<h4>必应</h4>
|
||||
</div>
|
||||
<div class="about-content">
|
||||
<p class="markdown"></p>
|
||||
<p class="markdown_content"></p>
|
||||
<span class="height-50"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -96,6 +96,13 @@
|
|||
<!-- footer end -->
|
||||
|
||||
<!--========= JS Here =========-->
|
||||
<script>
|
||||
MathJax = {
|
||||
tex: {
|
||||
inlineMath: [['$', '$'], ['\\(', '\\)']]
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<script src="{{pluResPath}}content/static/js/jquery-2.2.4.min.js"></script>
|
||||
<script src="{{pluResPath}}content/static/js/jquery.qrcode.min.js"></script>
|
||||
<script src="{{pluResPath}}content/static/js/highlight.min.js"></script>
|
||||
|
|
@ -119,11 +126,13 @@
|
|||
return hljs.highlightAuto(code,[lang]).value;
|
||||
}
|
||||
});
|
||||
const markdown = '{{@ content}}';
|
||||
const html = marked.parse(Base64.decode(markdown));
|
||||
const sanitizedHtml = DOMPurify.sanitize(html);
|
||||
const markdown_content = '{{@ content}}';
|
||||
const html_content = marked.parse(Base64.decode(markdown_content));
|
||||
const markdown_prompt = '{{@ prompt}}';
|
||||
const html_prompt = marked.parse(Base64.decode(markdown_prompt));
|
||||
|
||||
$(".markdown").html(sanitizedHtml);
|
||||
$(".markdown_content").html(DOMPurify.sanitize(html_content));
|
||||
$(".markdown_prompt").html(DOMPurify.sanitize(html_prompt));
|
||||
jQuery('#qrcode').qrcode({width: 128,height: 128,text: "{{cache.cacheUrl}}/{{cache.file}}"});
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@
|
|||
<h4>{{senderName}}</h4>
|
||||
</div>
|
||||
<div class="about-content">
|
||||
<h2>{{@ prompt}}</h2>
|
||||
<p class="markdown_prompt"></p>
|
||||
<span class="height-50"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -55,7 +55,7 @@
|
|||
<h4>ChatGPT</h4>
|
||||
</div>
|
||||
<div class="about-content">
|
||||
<p class="markdown"></p>
|
||||
<p class="markdown_content"></p>
|
||||
<span class="height-50"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -82,6 +82,13 @@
|
|||
<!-- footer end -->
|
||||
|
||||
<!--========= JS Here =========-->
|
||||
<script>
|
||||
MathJax = {
|
||||
tex: {
|
||||
inlineMath: [['$', '$'], ['\\(', '\\)']]
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<script src="{{pluResPath}}content/static/js/jquery-2.2.4.min.js"></script>
|
||||
<script src="{{pluResPath}}content/static/js/jquery.qrcode.min.js"></script>
|
||||
<script src="{{pluResPath}}content/static/js/highlight.min.js"></script>
|
||||
|
|
@ -105,11 +112,13 @@
|
|||
return hljs.highlightAuto(code,[lang]).value;
|
||||
}
|
||||
});
|
||||
const markdown = '{{@ content}}';
|
||||
const html = marked.parse(Base64.decode(markdown));
|
||||
const sanitizedHtml = DOMPurify.sanitize(html);
|
||||
const markdown_content = '{{@ content}}';
|
||||
const html_content = marked.parse(Base64.decode(markdown_content));
|
||||
const markdown_prompt = '{{@ prompt}}';
|
||||
const html_prompt = marked.parse(Base64.decode(markdown_prompt));
|
||||
|
||||
$(".markdown").html(sanitizedHtml);
|
||||
$(".markdown_content").html(DOMPurify.sanitize(html_content));
|
||||
$(".markdown_prompt").html(DOMPurify.sanitize(html_prompt));
|
||||
jQuery('#qrcode').qrcode({width: 128,height: 128,text: "{{cache.cacheUrl}}/{{cache.file}}"});
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue