From 3b1dad368eeefaa086f3c6611f119a6a82222302 Mon Sep 17 00:00:00 2001 From: zhiyu1998 Date: Sun, 9 Apr 2023 18:27:43 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E6=96=B0=E5=A2=9E=E5=AE=9E?= =?UTF-8?q?=E9=AA=8C=E6=8C=87=E4=BB=A4=EF=BC=9A#ocr=20=E5=AF=B9=E6=88=AA?= =?UTF-8?q?=E5=9B=BE=E7=9A=84=E5=86=85=E5=AE=B9=E8=BF=9B=E8=A1=8C=E6=80=BB?= =?UTF-8?q?=E7=BB=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tools.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ config/help.yaml | 3 +++ 2 files changed, 47 insertions(+) diff --git a/apps/tools.js b/apps/tools.js index 0677036..feb47fa 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -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; diff --git a/config/help.yaml b/config/help.yaml index 9be2df4..98d5e3e 100644 --- a/config/help.yaml +++ b/config/help.yaml @@ -64,3 +64,6 @@ - icon: update title: "#R插件更新" desc: "进行更新R插件" + - icon: computer + title: "【实验指令】#ocr" + desc: "基于gpt的识图总结" \ No newline at end of file