From 482aa29b004bc745ab519972f285d21342f901fb Mon Sep 17 00:00:00 2001 From: zhiyu1998 <542716863@qq.com> Date: Wed, 29 May 2024 20:18:37 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E6=B7=BB=E5=8A=A0=20ArXiv?= =?UTF-8?q?=E8=AE=BA=E6=96=87=20=E5=88=86=E4=BA=AB=E6=80=BB=E7=BB=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tools.js | 43 +++++++++++++++++++++++++++++++++---------- constants/constant.js | 2 +- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/apps/tools.js b/apps/tools.js index 97d4695..62b1397 100644 --- a/apps/tools.js +++ b/apps/tools.js @@ -175,8 +175,8 @@ export class tools extends plugin { fnc: "freyr" }, { - reg: "mp.weixin", - fnc: "weixin" + reg: "(mp.weixin|arxiv.org)", + fnc: "linkShareSummary" } ], }); @@ -1554,27 +1554,50 @@ export class tools extends plugin { return { title, album, artist }; } - async weixin(e) { + async linkShareSummary(e) { // 判断是否有总结的条件 if (_.isEmpty(this.aiApiKey) || _.isEmpty(this.aiApiKey)) { - e.reply(`没有配置 Kimi,无法为您的微信文章总结!${HELP_DOC}`) + e.reply(`没有配置 Kimi,无法为您总结!${HELP_DOC}`) return true; } - const urlReg = /(?:https?:\/\/)?mp\.weixin\.qq\.com\/[A-Za-z\d._?%&+\-=\/#]*/g; - const wxUrl = urlReg.exec(e.msg)?.[0]; + const { name, summaryLink } = this.contentEstimator(e.msg); const builder = await new OpenaiBuilder() .setBaseURL(this.aiBaseURL) .setApiKey(this.aiApiKey) .setModel(this.aiModel) .setPrompt(SUMMARY_PROMPT) .build(); - e.reply(`识别:微信文章,正在为您总结,请稍等...`); - const { ans: kimiAns, model } = await builder.kimi(wxUrl); - let Msg = await this.makeForwardMsg(e, [`「R插件 x ${ model }」联合为您总结内容:`,kimiAns]); - await e.reply(Msg); + e.reply(`识别:${name},正在为您总结,请稍等...`); + const { ans: kimiAns, model } = await builder.kimi(summaryLink); + // const Msg = await this.makeForwardMsg(e, [`「R插件 x ${ model }」联合为您总结内容:`,kimiAns]); + await e.reply(`「R插件 x ${ model }」联合为您总结内容:${kimiAns}`); return true; } + /** + * 内容评估器 + * @link {weixin} + * @param link 链接 + */ + contentEstimator(link) { + const wxReg = /(?:https?:\/\/)?mp\.weixin\.qq\.com\/[A-Za-z\d._?%&+\-=\/#]*/; + const arxivReg = /(?:https?:\/\/)?arxiv.org\/[a-zA-Z\d._?%&+\-=\/#]*/; + if (wxReg.test(link)) { + return { + name: '微信文章', + summaryLink: wxReg.exec(link)?.[0] + }; + } else if (arxivReg.test(link)) { + return { + name: 'ArXiv论文', + summaryLink: arxivReg.exec(link)?.[0] + }; + } else { + logger.error("[R插件][总结模块] 内容评估出错..."); + throw Error("内容评估出错..."); + } + } + /** * 哔哩哔哩下载 * @param title diff --git a/constants/constant.js b/constants/constant.js index 179b2f3..3ae386a 100644 --- a/constants/constant.js +++ b/constants/constant.js @@ -91,6 +91,6 @@ export const OCR_PROMPT = ` 示例:▲ 文本编辑器中的代码行。▲ const x = 5; const y = 10; const z = x + y; console.log(z); ` -export const SUMMARY_PROMPT = `请返回您仔细阅读正文后精心写成的详尽笔记` +export const SUMMARY_PROMPT = `请返回您仔细阅读正文后精心写成的详尽笔记,如果是ArXiv论文就简要介绍下内容和创新点即可` export const HELP_DOC = "\n文档:https://gitee.com/kyrzy0416/rconsole-plugin" \ No newline at end of file