mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-06-04 21:01:17 +08:00
feat: ai 评论 (#462)
Some checks failed
Build and push Docker images / docker (push) Has been cancelled
Mirror and run GitLab CI / build (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, linux) (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, macos) (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, win) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (alpine) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (linux) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (linuxstatic) (push) Has been cancelled
Some checks failed
Build and push Docker images / docker (push) Has been cancelled
Mirror and run GitLab CI / build (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, linux) (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, macos) (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, win) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (alpine) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (linux) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (linuxstatic) (push) Has been cancelled
* feat: ai content * style: 更改ai调用方式
This commit is contained in:
parent
ebb561c312
commit
b74bb02c65
@ -104,5 +104,16 @@ module.exports = Object.freeze({
|
|||||||
SMTP_TO_USER: '',
|
SMTP_TO_USER: '',
|
||||||
GOTIFY_URL: '',
|
GOTIFY_URL: '',
|
||||||
GOTIFY_APPKEY: ''
|
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 { send } = require('../net/http');
|
||||||
const bili = require('../net/bili');
|
const bili = require('../net/bili');
|
||||||
const { sendNotify } = require('../helper/notify');
|
const { sendNotify } = require('../helper/notify');
|
||||||
@ -281,7 +281,7 @@ class Monitor extends Searcher {
|
|||||||
reserve_lottery_wait, sneaktower, key_words,
|
reserve_lottery_wait, sneaktower, key_words,
|
||||||
model, chatmodel, chat: chats, relay: relays,
|
model, chatmodel, chat: chats, relay: relays,
|
||||||
block_dynamic_type, max_create_time, is_imitator,
|
block_dynamic_type, max_create_time, is_imitator,
|
||||||
only_followed, at_users, blockword, blacklist,
|
only_followed, at_users, blockword, blacklist,use_ai_comments
|
||||||
} = config,
|
} = config,
|
||||||
now_ts = Date.now() / 1000;
|
now_ts = Date.now() / 1000;
|
||||||
|
|
||||||
@ -527,8 +527,19 @@ class Monitor extends Searcher {
|
|||||||
/* 是否评论 */
|
/* 是否评论 */
|
||||||
if (isSendChat) {
|
if (isSendChat) {
|
||||||
onelotteryinfo.rid = rid;
|
onelotteryinfo.rid = rid;
|
||||||
onelotteryinfo.chat = (getRandomOne(chats) || '!!!')
|
if (use_ai_comments) {
|
||||||
.replace(/\$\{uname\}/g, uname);
|
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);
|
alllotteryinfo.push(onelotteryinfo);
|
||||||
|
|||||||
@ -13,7 +13,8 @@ const env = {
|
|||||||
const raw_env = this.raw_env();
|
const raw_env = this.raw_env();
|
||||||
this.setEnv({
|
this.setEnv({
|
||||||
...raw_env['account_parm'],
|
...raw_env['account_parm'],
|
||||||
...raw_env['push_parm']
|
...raw_env['push_parm'],
|
||||||
|
...raw_env['ai_parm']
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|||||||
45
lib/utils.js
45
lib/utils.js
@ -508,7 +508,50 @@ const utils = {
|
|||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.error('获取' + printMessage + '地址失败', err);
|
console.error('获取' + printMessage + '地址失败', err);
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
|
/**
|
||||||
|
* 获取ai评论
|
||||||
|
* @param {string} content
|
||||||
|
* @returns {Promise<string|null>}
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -459,7 +459,14 @@ module.exports = Object.freeze({
|
|||||||
* 1
|
* 1
|
||||||
* [1,2,4]
|
* [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