From 1e5265494475456cb1dcaf8ae026fb385e7ace95 Mon Sep 17 00:00:00 2001 From: zhiyu1998 <542716863@qq.com> Date: Fri, 19 Jul 2024 17:26:42 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E6=96=B0=E5=A2=9E`#rpt`?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E6=B6=88=E6=81=AF=E5=BC=95=E7=94=A8=E7=9A=84?= =?UTF-8?q?=E8=AF=86=E5=9B=BE=E5=92=8C=E5=9B=BE=E7=89=87=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tools.js | 41 ++++++++++++++++++++++++++++++++++++++++- constants/constant.js | 6 ++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/apps/tools.js b/apps/tools.js index 434ef56..7b87e55 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -26,7 +26,7 @@ import { BILI_DEFAULT_INTRO_LEN_LIMIT, DIVIDING_LINE, douyinTypeMap, - HELP_DOC, + HELP_DOC, IMAGE_TRANSLATION_PROMPT, REDIS_YUNZAI_ISOVERSEA, REDIS_YUNZAI_LAGRANGE, SUMMARY_PROMPT, @@ -185,6 +185,10 @@ export class tools extends plugin { { reg: "(mp.weixin|arxiv.org|sspai.com|chinadaily.com.cn)", fnc: "linkShareSummary" + }, + { + reg: "#(RPT|rpt)$", + fnc: "pictureTranslate" } ], }); @@ -413,6 +417,7 @@ export class tools extends plugin { }); } + // 哔哩哔哩扫码登录 async biliScan(e) { e.reply('R插件开源免责声明:\n您将通过扫码完成获取哔哩哔哩refresh_token以及ck。\n本Bot将不会保存您的登录状态。\n我方仅提供视频解析及相关B站内容服务,若您的账号封禁、被盗等处罚与我方无关。\n害怕风险请勿扫码 ~', { recallMsg: 180 }); // 图片发送钩子 @@ -435,6 +440,7 @@ export class tools extends plugin { // bilibi解析 async bili(e) { + // 限制用户密集使用的 AOP await this.limitUserUse(e, () => { this.biliCore(e); }); @@ -1617,6 +1623,39 @@ export class tools extends plugin { return true; } + async pictureTranslate(e) { + // logger.info(Bot.pickGroup(e.group_id, true)) + const curGroup = Bot.pickGroup(e.group_id, true); + const curGroupMessages = await curGroup.getChatHistory(e.message_seq, 1); + const groupMessage = curGroupMessages.pop()?.message; + // logger.info(groupMessage) + let refImgUrl; + for (let itemMessage of groupMessage) { + if (itemMessage.type === 'reply') { + const imgMessage = await curGroup.getMsg(itemMessage.id); + // logger.info(imgMessage) + refImgUrl = imgMessage.message.pop()?.url; + } + } + if (refImgUrl === undefined || refImgUrl == null) { + e.reply("无法检测到图片,请重试!"); + return + } + const builder = await new OpenaiBuilder() + .setBaseURL(this.aiBaseURL) + .setApiKey(this.aiApiKey) + .setModel(this.aiModel) + .setPrompt(IMAGE_TRANSLATION_PROMPT) + .build(); + e.reply(`识别:图片翻译,请稍等...`, true, { recallMsg: 60 }); + const refImgDownloadPath = this.getCurDownloadPath(e); + await downloadImg(refImgUrl, refImgDownloadPath, "demo.png"); + const { ans: kimiAns, model } = await builder.openai_pic(`${refImgDownloadPath}/demo.png`); + const Msg = await this.makeForwardMsg(e, [`「R插件 x ${ model }」联合为您识别内容:`, kimiAns]); + await e.reply(Msg); + return true; + } + /** * 哔哩哔哩下载 * @param title diff --git a/constants/constant.js b/constants/constant.js index ce83a02..8476708 100644 --- a/constants/constant.js +++ b/constants/constant.js @@ -99,6 +99,12 @@ export const BILI_DEFAULT_INTRO_LEN_LIMIT = 50; */ export const SUMMARY_PROMPT = `请返回您仔细阅读正文后精心写成的详尽笔记,如果是ArXiv论文就简要介绍下内容和创新点即可` +/** + * 图片翻译 prompt + * @type {string} + */ +export const IMAGE_TRANSLATION_PROMPT = `Begin each of the following with a triangle symbol (▲ U+25B2): First, a brief description of the image to be used as alt text. Do not describe or extract text in the description. Second, the text extracted from the image, with newlines where applicable. Un-obstruct text if it is covered by something, to make it readable. If there is no text in the image, only respond with the description. Do not include any other information. Example: ▲ Lines of code in a text editor.▲ const x = 5; const y = 10; const z = x + y; console.log(z); Finally, answer in Chinese.` + /** * 帮助文档提示 * @type {string}