Add simple GPT functionality to your Discord bot with this snippet! When you mention the bot and ask it a question, it'll reply with its best answer.
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let prompt = [
`You are a Discord bot in someone's server.`,
`They asked you this question: ${context.params.event.content}`,
`Please reply with the most accurate answer that you can.`,
].join('\n');
let answer = await lib.openai.playground['@0.0.3'].completions.create({
model: `text-davinci-003`,
prompt: [`${prompt}`],
max_tokens: 512,
temperature: 0.5,
top_p: 1,
n: 1,
echo: false,
presence_penalty: 0,
frequency_penalty: 0,
best_of: 1,
});
await lib.discord.channels['@0.3.4'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `${answer.choices[0].text}`,
});