UNPKG

koishi-plugin-nitter-rss

Version:

订阅 X (Twitter) 内容,使用 nitter.cz,支持ChatGPT与Gradio Chatbot翻译

30 lines (29 loc) 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GradioChatBotParse = void 0; const koishi_1 = require("koishi"); const gradio_chatbot_1 = require("gradio-chatbot"); const logger = new koishi_1.Logger('nitter-rss-gradio-chatbot'); async function GradioChatBotParse(content, config) { logger.info(`正在使用ID: ${config.GradioChatBotModule} 模型`); const bot = new gradio_chatbot_1.GradioChatBot(config.GradioChatBotModule); logger.info(`AI翻译开始`); const maxRetry = 3; let retry = 0; while (retry < maxRetry) { try { const result = await bot.chat(`${content}`); if (result == '') { throw new Error(`AI翻译失败`); } return result; } catch (e) { retry++; logger.warn(`AI翻译失败,正在重试(${retry}/${maxRetry})`); await new Promise(resolve => setTimeout(resolve, 1000)); } } throw new Error(`AI翻译失败`); } exports.GradioChatBotParse = GradioChatBotParse;