feat: 添加 ArXiv论文 分享总结

This commit is contained in:
zhiyu1998 2024-05-29 20:18:37 +08:00
parent 56e6484642
commit 482aa29b00
2 changed files with 34 additions and 11 deletions

View File

@ -175,8 +175,8 @@ export class tools extends plugin {
fnc: "freyr" fnc: "freyr"
}, },
{ {
reg: "mp.weixin", reg: "(mp.weixin|arxiv.org)",
fnc: "weixin" fnc: "linkShareSummary"
} }
], ],
}); });
@ -1554,27 +1554,50 @@ export class tools extends plugin {
return { title, album, artist }; return { title, album, artist };
} }
async weixin(e) { async linkShareSummary(e) {
// 判断是否有总结的条件 // 判断是否有总结的条件
if (_.isEmpty(this.aiApiKey) || _.isEmpty(this.aiApiKey)) { if (_.isEmpty(this.aiApiKey) || _.isEmpty(this.aiApiKey)) {
e.reply(`没有配置 Kimi无法为您的微信文章总结!${HELP_DOC}`) e.reply(`没有配置 Kimi无法为您总结!${HELP_DOC}`)
return true; return true;
} }
const urlReg = /(?:https?:\/\/)?mp\.weixin\.qq\.com\/[A-Za-z\d._?%&+\-=\/#]*/g; const { name, summaryLink } = this.contentEstimator(e.msg);
const wxUrl = urlReg.exec(e.msg)?.[0];
const builder = await new OpenaiBuilder() const builder = await new OpenaiBuilder()
.setBaseURL(this.aiBaseURL) .setBaseURL(this.aiBaseURL)
.setApiKey(this.aiApiKey) .setApiKey(this.aiApiKey)
.setModel(this.aiModel) .setModel(this.aiModel)
.setPrompt(SUMMARY_PROMPT) .setPrompt(SUMMARY_PROMPT)
.build(); .build();
e.reply(`识别:微信文章,正在为您总结,请稍等...`); e.reply(`识别:${name},正在为您总结,请稍等...`);
const { ans: kimiAns, model } = await builder.kimi(wxUrl); const { ans: kimiAns, model } = await builder.kimi(summaryLink);
let Msg = await this.makeForwardMsg(e, [`「R插件 x ${ model }」联合为您总结内容:`,kimiAns]); // const Msg = await this.makeForwardMsg(e, [`「R插件 x ${ model }」联合为您总结内容:`,kimiAns]);
await e.reply(Msg); await e.reply(`「R插件 x ${ model }」联合为您总结内容:${kimiAns}`);
return true; 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 * @param title

View File

@ -91,6 +91,6 @@ export const OCR_PROMPT = `
示例 文本编辑器中的代码行 const x = 5; const y = 10; const z = x + y; console.log(z); 示例 文本编辑器中的代码行 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" export const HELP_DOC = "\n文档https://gitee.com/kyrzy0416/rconsole-plugin"