koishi-plugin-nitter-rss
Version:
订阅 X (Twitter) 内容,使用 nitter.cz,支持ChatGPT与Gradio Chatbot翻译
34 lines (33 loc) • 1.17 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChatGPTParse = void 0;
const koishi_1 = require("koishi");
const openai_1 = __importDefault(require("openai"));
const logger = new koishi_1.Logger('nitter-rss-chatgpt');
async function ChatGPTParse(prompt, apiKey, baseURL, model) {
if (apiKey == '' || apiKey == undefined) {
throw new Error(`ChatGPT API Key为空`);
}
logger.info(`ChatGPT翻译开始`);
const openai = new openai_1.default({
baseURL: baseURL,
apiKey: apiKey,
});
let response = '';
const chatCompletion = await openai.chat.completions.create({
messages: [{ role: "user", content: prompt }],
model: model,
});
response += chatCompletion.choices[0].message.content;
if (response == '') {
throw new Error(`ChatGPT翻译失败`);
}
if (chatCompletion.choices[0].finish_reason == 'length') {
response += '\n...';
}
return response;
}
exports.ChatGPTParse = ChatGPTParse;