Implement early AI integration #18
All checks were successful
release-tag / release-image (push) Successful in 4m19s
DRB Tests / drb_mocha_tests (push) Successful in 1m16s

- 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
This commit is contained in:
Logan Cusano
2024-06-02 19:16:01 -04:00
parent 2c3cc18474
commit 961a7cc2bd
5 changed files with 205 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
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;
}
}