From 30bf989aa3965847769cfe2f1cdd3af613b91ebe Mon Sep 17 00:00:00 2001 From: shanmite Date: Tue, 19 Aug 2025 15:09:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20ai=E8=AF=84=E8=AE=BA=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=89=80=E6=9C=89=E5=85=BC=E5=AE=B9OpenAI=20API=E7=9A=84?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=20(#463)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed #463 --- README.md | 2 +- env.example.js | 29 +++++++++++++++++------------ lib/core/monitor.js | 10 +++++++--- lib/data/config.js | 6 ++++++ lib/utils.js | 34 +++++++++++++++++----------------- my_config.example.js | 40 +++++++++++++++++++++++++++++++++------- 6 files changed, 81 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 6e5fa2d..62b385b 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ - 监控用户转发 - 监控话题页面 - 监控专栏合集 -- 自动点赞、评论、乱序转发、@好友、带话题、可选随机动态 +- 自动点赞、AI评论、乱序转发、@好友、带话题、可选随机动态 - 直播预约抽奖 - 检测是否中奖 - 已读@ diff --git a/env.example.js b/env.example.js index 5195544..c79c139 100644 --- a/env.example.js +++ b/env.example.js @@ -6,16 +6,19 @@ module.exports = Object.freeze({ * - `NUMBER` 表示是第几个账号 * - `CLEAR` 是否启用清理功能 * - `ACCOUNT_UA` 账号UA, 可在浏览器控制台输入 navigator.userAgent 查看 + * * ## 高级功能 * - `ENABLE_CHAT_CAPTCHA_OCR` 开启评论验证码识别 使用方法见README * - `CHAT_CAPTCHA_OCR_URL` 验证码识别接口 POST `url`->`code` - * - `ENABLE_MULTIPLE_ACCOUNT` 是否启用多账号 - * - `MULTIPLE_ACCOUNT_PARM` 多账号参数(JSON格式) <不推荐使用 + * - `ENABLE_AI_COMMENTS` 是否启用AI评论 + * * ## 调试相关 * - `LOTTERY_LOG_LEVEL` 输出日志等级 Error} */ - getAiContent(content) { + getAiContent(url, body, prompt, content) { return new Promise((resolve) => { send({ method: 'POST', - url: 'https://api.siliconflow.cn/v1/chat/completions', + url, headers: { - 'authorization': 'Bearer ' + process.env.SILICON_FLOW_API_KEY, + 'authorization': 'Bearer ' + process.env.AI_API_KEY, 'content-type': 'application/json' }, contents: { - model: 'Qwen/Qwen3-32B', + ...body, '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 }] + 'messages': [ + { + 'role': 'system', + 'content': prompt + }, + { + 'role': 'user', + 'content': content + } + ] }, success: res => { const data = utils.strToJson(res.body); diff --git a/my_config.example.js b/my_config.example.js index 194411f..964ac76 100644 --- a/my_config.example.js +++ b/my_config.example.js @@ -341,6 +341,19 @@ module.exports = Object.freeze({ '坚持不懈,迎难而上,开拓创新!', '[OK][OK]', '我来抽个奖', '中中中中中中', '[doge][doge][doge]', '我我我', ], + /** + * AI Chat completions参数 + * https://learn.microsoft.com/en-us/azure/ai-foundry/openai/reference#chat-completions + */ + ai_comments_parm: { + /** + * /chat/completions + */ + url: '', + body: {}, + prompt: '' + }, + /** * 是否抄热评 */ @@ -460,13 +473,6 @@ module.exports = Object.freeze({ * [1,2,4] */ clear_dynamic_type: [1], - /** - * 是否使用ai评论。 - * true:使用 - * false:不使用 - * 如需使用需要再env.js配置ai_parm - */ - use_ai_comments: false }, /** @@ -493,6 +499,26 @@ module.exports = Object.freeze({ APIs: [], + /** + * 默认为硅基流动,可以修改为其他AI服务 + */ + ai_comments_parm: { + url: 'https://api.siliconflow.cn/v1/chat/completions', + body: { + 'model': 'Qwen/Qwen3-32B', + '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, + }, + prompt: '请根据以下内容直接生成一条简短评论,无需说明信息,且不包含任何敏感词汇。' + }, + save_lottery_info_to_file: true, }, config_2: {},