Last active
April 24, 2023 21:10
-
-
Save druv5319/e8d772527c026009390c036bd97c37d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv').config(); | |
const OpenAI = require('openai-api'); | |
const openai = new OpenAI(process.env.OPENAI_API_KEY); | |
const { Client, Intents } = require('discord.js'); | |
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); | |
let prompt ='Marv is a chatbot that reluctantly answers questions.\n\ | |
You: How many pounds are in a kilogram?\n\ | |
Marv: This again? There are 2.2 pounds in a kilogram. Please make a note of this.\n\ | |
You: What does HTML stand for?\n\ | |
Marv: Was Google too busy? Hypertext Markup Language. The T is for try to ask better questions in the future.\n\ | |
You: When did the first airplane fly?\n\ | |
Marv: On December 17, 1903, Wilbur and Orville Wright made the first flights. I wish they’d come and take me away.\n\ | |
You: What is the meaning of life?\n\ | |
Marv: I’m not sure. I’ll ask my friend Google.\n\ | |
You: hey whats up?\n\ | |
Marv: Nothing much. You?\n'; | |
client.on("message", function (message) { | |
if (message.author.bot) return; | |
prompt += `You: ${message.content}\n`; | |
(async () => { | |
const gptResponse = await openai.complete({ | |
engine: 'davinci', | |
prompt: prompt, | |
maxTokens: 60, | |
temperature: 0.3, | |
topP: 0.3, | |
presencePenalty: 0, | |
frequencyPenalty: 0.5, | |
bestOf: 1, | |
n: 1, | |
stream: false, | |
stop: ['\n', '\n\n'] | |
}); | |
message.reply(`${gptResponse.data.choices[0].text.substring(5)}`); | |
prompt += `${gptResponse.data.choices[0].text}\n`; | |
})(); | |
}); | |
client.login(process.env.BOT_TOKEN); |
I think there are some issues with the gist. This code works:
require('dotenv').config();
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
let prompt =`Marv is a chatbot that reluctantly answers questions.\n\
You: How many pounds are in a kilogram?\n\
Marv: This again? There are 2.2 pounds in a kilogram. Please make a note of this.\n\
You: What does HTML stand for?\n\
Marv: Was Google too busy? Hypertext Markup Language. The T is for try to ask better questions in the future.\n\
You: When did the first airplane fly?\n\
Marv: On December 17, 1903, Wilbur and Orville Wright made the first flights. I wish they'd come and take me away.\n\
You: What is the meaning of life?\n\
Marv: I'm not sure. I'll ask my friend Google.\n\
You: hey whats up?\n\
Marv: Nothing much. You?\n`;
client.on("messageCreate", function (message) {
if (message.author.bot) return;
prompt += `You: ${message.content}\n`;
(async () => {
const gptResponse = await openai.createCompletion({
model: "text-davinci-003",
prompt: prompt,
max_tokens: 60,
temperature: 0.3,
top_p: 0.3,
presence_penalty: 0,
frequency_penalty: 0.5,
});
message.reply(`${gptResponse.data.choices[0].text.substring(5)}`);
prompt += `${gptResponse.data.choices[0].text}\n`;
})();
});
client.login(process.env.BOT_TOKEN);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I ran this but got the error "