mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-06-04 21:01:17 +08:00
feat: ai content
This commit is contained in:
parent
ebb561c312
commit
22ccfaae2a
@ -104,5 +104,16 @@ module.exports = Object.freeze({
|
||||
SMTP_TO_USER: '',
|
||||
GOTIFY_URL: '',
|
||||
GOTIFY_APPKEY: ''
|
||||
},
|
||||
|
||||
/**
|
||||
* ai相关参数
|
||||
*/
|
||||
ai_parm: {
|
||||
//硅基流动apikey
|
||||
SILICON_FLOW_API_KEY:'',
|
||||
//提示词
|
||||
PROMPT:''
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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']
|
||||
});
|
||||
},
|
||||
/**
|
||||
|
||||
48
lib/utils.js
48
lib/utils.js
@ -508,7 +508,53 @@ const utils = {
|
||||
}).catch((err) => {
|
||||
console.error('获取' + printMessage + '地址失败', err);
|
||||
});
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 获取ai评论
|
||||
* @returns Promise
|
||||
* @param content
|
||||
*/
|
||||
getAiContent(content) {
|
||||
const options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + process.env.SILICON_FLOW_API_KEY,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
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 }]
|
||||
})
|
||||
};
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch('https://api.siliconflow.cn/v1/chat/completions', options).then(response => {
|
||||
if (response.status === 200) {
|
||||
response.json().then(data => {
|
||||
resolve(data?.choices[0].message.content || null);
|
||||
});
|
||||
} else {
|
||||
reject(null);
|
||||
}
|
||||
}).catch(() => {
|
||||
reject(null);
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user