I have been trying this many times over with no success. Basically, just a simple discord bot that retrieves messages and uses them as context as well as user message as prompt. This code framework works great with gpt3.5-turbo. But I have altered it to try and use the Davinci model, with no luck. At one point it was recommended to me to add the prompt line for join.
I am idk, noobish, at javascript and OpenAI API, this is my fifth bot.
require('dotenv/config');
const { Client, IntentsBitField } = require('discord.js');
const { Configuration, OpenAIApi } = require('openai');
const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
});
client.on('ready', () => {
console.log('The bot is online!');
});
const configuration = new Configuration({
apiKey: process.env.API_KEY,
});
const openai = new OpenAIApi(configuration);
client.on('messageCreate', async (message) => {
if (message.author.bot) return;
if (message.author.bot || !message.mentions.has(client.user.id)) return;
if (!message.mentions.has(client.user) && !message.reference?.messageId === client.user.id) return;
let conversationLog = [{ role: 'system', content: 'You are a friendly chatbot.' }];
try {
await message.channel.sendTyping();
let prevMessages = await message.channel.messages.fetch({ limit: 5 });
prevMessages.reverse();
prevMessages.forEach((msg) => {
conversationLog.push({
role: 'user',
content: msg.content,
});
});
const prompt = conversationLog.map(({ content }) => content).join('\n');
const result = await openai.createChatCompletion({
prompt: prompt,
model: "davinci",
max_tokens: 2500,
temperature: 0.3,
top_p: 0.3,
presence_penalty: 0,
frequency_penalty: 0.5,
context: conversationLog,
})
const generatedText = result.data.choices[0].text;
return message.reply(generatedText);
} catch (error) {
console.log(`ERR: ${error}`);
}
});
client.login(process.env.TOKEN);