添加图片识别配置项

This commit is contained in:
Alcedo 2023-02-24 11:56:58 +08:00
parent c5087e364e
commit f685e94061
4 changed files with 36 additions and 26 deletions

View file

@ -267,37 +267,39 @@ export class chatgpt extends plugin {
return false
}
}
// 取消息中的图片、at的头像、回复的图片放入e.img
if (e.at && !e.source) {
e.img = [`https://q1.qlogo.cn/g?b=qq&s=0&nk=${e.at}`];
}
if (e.source) {
let reply;
if (e.isGroup) {
reply = (await e.group.getChatHistory(e.source.seq, 1)).pop()?.message;
} else {
reply = (await e.friend.getChatHistory(e.source.time, 1)).pop()?.message;
if (Config.imgOcr) {
// 取消息中的图片、at的头像、回复的图片放入e.img
if (e.at && !e.source) {
e.img = [`https://q1.qlogo.cn/g?b=qq&s=0&nk=${e.at}`];
}
if (reply) {
for (let val of reply) {
if (val.type == "image") {
e.img = [val.url];
break;
if (e.source) {
let reply;
if (e.isGroup) {
reply = (await e.group.getChatHistory(e.source.seq, 1)).pop()?.message;
} else {
reply = (await e.friend.getChatHistory(e.source.time, 1)).pop()?.message;
}
if (reply) {
for (let val of reply) {
if (val.type == "image") {
e.img = [val.url];
break;
}
}
}
}
}
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`
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`
}
prompt = imgtext + prompt
}
prompt = imgtext + prompt
}
} catch (err) {}
} catch (err) {}
}
}
// 检索是否有屏蔽词
const promtBlockWord = promptBlockWords.find(word => prompt.toLowerCase().includes(word.toLowerCase()))

View file

@ -11,6 +11,7 @@ export default {
// blockWords: ['屏蔽词1', '屏蔽词b'],
// 问题中如果触发屏蔽词,也会拒绝回答
// promptBlockWords: ['屏蔽词1', '屏蔽词b'],
// imgOcr: true,
// 改为true后全局默认以图片形式回复并自动发出Continue命令补全回答。长回复可能会有bug。
// defaultUsePicture: false,
// 如果true字数大于阈值autoUsePictureThreshold会自动用图片发送即使是文本模式。

View file

@ -25,6 +25,12 @@ export function supportGuoba() {
configInfo: {
// 配置项 schemas
schemas: [
{
field: 'imgOcr',
label: '图片识别',
bottomHelpMessage: '是否识别消息中图片的文字内容,需要同时包含图片和消息才生效',
component: 'Switch',
},
{
field: 'defaultUsePicture',
label: '全局图片模式',

View file

@ -3,6 +3,7 @@ import lodash from 'lodash'
const defaultConfig = {
blockWords: ['屏蔽词1', '屏蔽词b'],
promptBlockWords: ['屏蔽词1', '屏蔽词b'],
imgOcr: true,
defaultUsePicture: false,
autoUsePicture: true,
autoUsePictureThreshold: 1200,