diff --git a/env.example.js b/env.example.js index e3c4427..9d6109b 100644 --- a/env.example.js +++ b/env.example.js @@ -104,5 +104,16 @@ module.exports = Object.freeze({ SMTP_TO_USER: '', GOTIFY_URL: '', GOTIFY_APPKEY: '' + }, + + /** + * ai相关参数 + */ + ai_parm: { + //硅基流动apikey + SILICON_FLOW_API_KEY:'', + //提示词 + PROMPT:'' + } }); diff --git a/lib/core/monitor.js b/lib/core/monitor.js index 874a91e..f9645f6 100644 --- a/lib/core/monitor.js +++ b/lib/core/monitor.js @@ -1,4 +1,4 @@ -const { log, hasEnv, shuffle, getRandomOne, delay, try_for_each, retryfn, appendLotteryInfoFile } = require('../utils'); +const { log, hasEnv, shuffle, getRandomOne,getAiContent, delay, try_for_each, retryfn, appendLotteryInfoFile } = require('../utils'); const { send } = require('../net/http'); const bili = require('../net/bili'); const { sendNotify } = require('../helper/notify'); @@ -281,7 +281,7 @@ class Monitor extends Searcher { reserve_lottery_wait, sneaktower, key_words, model, chatmodel, chat: chats, relay: relays, block_dynamic_type, max_create_time, is_imitator, - only_followed, at_users, blockword, blacklist, + only_followed, at_users, blockword, blacklist,use_ai_comments } = config, now_ts = Date.now() / 1000; @@ -527,8 +527,19 @@ class Monitor extends Searcher { /* 是否评论 */ if (isSendChat) { onelotteryinfo.rid = rid; - onelotteryinfo.chat = (getRandomOne(chats) || '!!!') - .replace(/\$\{uname\}/g, uname); + if (use_ai_comments) { + try { + log.info('开始获取Ai评论', `(https://t.bilibili.com/${dyid})`); + onelotteryinfo.chat = await getAiContent(lottery_info.des); + //(getRandomOne(chats) || '!!!').replace(/\$\{uname\}/g, uname); + log.info('Ai评论内容', `${onelotteryinfo.chat}`); + } catch (e) { + log.error('获取AI评论失败,使用随机评论', e); + onelotteryinfo.chat = (getRandomOne(chats) || '!!!').replace(/\$\{uname\}/g, uname); + } + } else { + onelotteryinfo.chat = (getRandomOne(chats) || '!!!').replace(/\$\{uname\}/g, uname); + } } alllotteryinfo.push(onelotteryinfo); diff --git a/lib/data/env.js b/lib/data/env.js index 992898a..70d040b 100644 --- a/lib/data/env.js +++ b/lib/data/env.js @@ -13,7 +13,8 @@ const env = { const raw_env = this.raw_env(); this.setEnv({ ...raw_env['account_parm'], - ...raw_env['push_parm'] + ...raw_env['push_parm'], + ...raw_env['ai_parm'] }); }, /** diff --git a/lib/utils.js b/lib/utils.js index 08ad090..c77bcd4 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -508,7 +508,50 @@ const utils = { }).catch((err) => { console.error('获取' + printMessage + '地址失败', err); }); - } + }, + /** + * 获取ai评论 + * @param {string} content + * @returns {Promise} + */ + getAiContent(content) { + return new Promise((resolve) => { + send({ + method: 'POST', + url: 'https://api.siliconflow.cn/v1/chat/completions', + headers: { + 'authorization': 'Bearer ' + process.env.SILICON_FLOW_API_KEY, + 'content-type': 'application/json' + }, + contents: { + model: 'Qwen/Qwen3-32B', + 'stream': false, + 'max_tokens': 512, + 'enable_thinking': true, + 'thinking_budget': 4096, + 'min_p': 0.05, + 'temperature': 0.7, + 'top_p': 0.7, + 'top_k': 50, + 'frequency_penalty': 0.5, + 'n': 1, + 'stop': [], + 'response_format': { 'type': 'text' }, + 'messages': [{ + 'role': 'system', + 'content': process.env.PROMPT + }, { 'role': 'user', 'content': content }] + }, + success: res => { + const data = utils.strToJson(res.body); + resolve(data?.choices?.[0]?.message?.content || null); + }, + failure: () => { + resolve(null); + } + }); + }); + }, }; diff --git a/my_config.example.js b/my_config.example.js index d8b727a..194411f 100644 --- a/my_config.example.js +++ b/my_config.example.js @@ -459,7 +459,14 @@ module.exports = Object.freeze({ * 1 * [1,2,4] */ - clear_dynamic_type: [1] + clear_dynamic_type: [1], + /** + * 是否使用ai评论。 + * true:使用 + * false:不使用 + * 如需使用需要再env.js配置ai_parm + */ + use_ai_comments: false }, /**