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