tardis-bot/modules/chatgpt/index.js

20 lines
556 B
JavaScript

let ChatGPTAPI = null;
module.exports = function (bot, api) {
import("chatgpt").then((mod) => {
ChatGPTAPI = mod.ChatGPTAPI;
});
api.registerCommand('chat', async (args, message) => {
const response = await getChatGPTResponse(message.content.slice(6).trim());
api.respond(message, response);
});
}
async function getChatGPTResponse(prompt) {
const api = new ChatGPTAPI({
apiKey: process.env.OPENAI_API_KEY
})
const res = await api.sendMessage(prompt);
return res.text;
}