Files
drb-server/discordBot/modules/gptHandler.mjs
Logan Cusano 961a7cc2bd
All checks were successful
release-tag / release-image (push) Successful in 4m19s
DRB Tests / drb_mocha_tests (push) Successful in 1m16s
Implement early AI integration #18
- Added new event to catch messageCreate events
- @ messages to the server will use ChatGPT to respond to the message with an indepth prompt about the server
- Implement module to interact with chatGPT repeatably
- Add linkcop with GPT integration #12
- Added environment variable for inital prompt for GPT integration
2024-06-02 19:16:01 -04:00

39 lines
1.1 KiB
JavaScript

import { DebugBuilder } from "../../modules/debugger.mjs";
const log = new DebugBuilder("server", "discordBot.modules.gptHandler");
import dotenv from 'dotenv';
dotenv.config();
import { OpenAI } from 'openai';
const openai = new OpenAI(process.env.OPENAI_API_KEY);
let conversation = [];
conversation.push({
role: 'system',
content: process.env.DRB_SERVER_INITIAL_PROMPT
});
export const gptHandler = async (additionalMessages) => {
// Add the additional messages to the conversation
conversation = conversation.concat(additionalMessages);
log.DEBUG("AI Conversation:", conversation);
try {
const response = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
messages: conversation,
}).catch((error) => log.ERROR("OpenAI Error: ", error));
log.DEBUG("AI Response:", response);
if (!response) {
return false;
}
return response
} catch (error) {
console.error('Error generating response:', error);
return false;
}
}