feat: 新增实验指令:#ocr 对截图的内容进行总结

This commit is contained in:
zhiyu1998 2023-04-09 18:27:43 +08:00
parent b7c11826cd
commit 3b1dad368e
2 changed files with 47 additions and 0 deletions

View File

@ -33,6 +33,10 @@ export class tools extends plugin {
reg: "^(翻|trans)(.*)$",
fnc: "trans",
},
{
reg: "^#ocr$",
fnc: "ocr2anything",
},
{
reg: "(v.douyin.com)",
fnc: "douyin",
@ -137,6 +141,46 @@ export class tools extends plugin {
return true;
}
// 图像识别文字
async ocr2anything(e) {
e.reply(" 👀请发送图片")
this.setContext("ocr2anythingContext");
return true;
}
/**
* 图像识别文字核心
* @link{ocr2anythingContext} 的上下文
* @return Promise{void}
**/
async ocr2anythingContext() {
// 当前消息
const curMsg = this.e;
try {
const defaultPath = `${this.defaultPath}${this.e.group_id || this.e.user_id}`
await this.downloadImg(curMsg.img, defaultPath, "temp.jpg").then(async _ => {
const ocrRst = await Bot.imageOcr(`${defaultPath}/temp.jpg`);
const wordList = ocrRst.wordslist;
let prompt = wordList.map(item => item.words);
logger.info(prompt)
if (this.openaiAccessToken) {
prompt = "Summarize the key points of this article in Chinese and in a list of points. Choose an appropriate emoji for each bullet point. Each bullet point format is [emoji] - [text]." + prompt.join(" ")
const response = await this.chatGptClient.sendMessage(prompt);
// 暂时不设计上下文
prompt = response.response;
} else {
prompt = prompt.join("\n")
}
curMsg.reply(prompt);
});
} catch (err) {
curMsg.reply("OCR失败")
} finally {
this.finish("ocr2anythingContext")
}
this.finish("ocr2anythingContext")
}
// 抖音解析
async douyin(e) {
const urlRex = /(http:|https:)\/\/v.douyin.com\/[A-Za-z\d._?%&+\-=\/#]*/g;

View File

@ -64,3 +64,6 @@
- icon: update
title: "#R插件更新"
desc: "进行更新R插件"
- icon: computer
title: "【实验指令】#ocr"
desc: "基于gpt的识图总结"