2023-03-21 12:35:28 +00:00
|
|
|
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({
|
2023-11-12 23:07:15 +00:00
|
|
|
apiKey: process.env.OPENAI_API_KEY,
|
|
|
|
completionParams: {
|
2024-12-26 19:31:04 +00:00
|
|
|
model: 'gpt-4o'
|
2023-11-12 23:07:15 +00:00
|
|
|
}
|
2023-03-21 12:35:28 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const res = await api.sendMessage(prompt);
|
|
|
|
return res.text;
|
|
|
|
}
|