Skip to content

Commit

Permalink
Changes on generate image and now there's text ai.
Browse files Browse the repository at this point in the history
  • Loading branch information
Neodevils committed Feb 18, 2023
1 parent cbb9ae6 commit 13d1ffd
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/commands/general/generate-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default {

if (interaction.channel.id === '1071856982748844124') {
if (interaction.author.bot) return;

try {
const imageUrl = await openai.createImage({
prompt: interaction.content,
Expand All @@ -44,7 +45,11 @@ export default {
});
interaction.reply({ content: `${imageUrl.data.data[0].url}` });
} catch (error) {
interaction.reply({ content: 'eh?' });
interaction.reply({
content:
"Couldn't generate that image... Am I the problem or you? Can't decide...",
ephemeral: true,
});
console.log(error);
}
}
Expand Down
66 changes: 66 additions & 0 deletions src/commands/general/text-to-ai.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { SlashCommandBuilder } from 'discord.js';
import { Configuration, OpenAIApi } from 'openai';
import config from '../../../config.js';

// Creating the command
export default {
data: new SlashCommandBuilder()
.setName('ask-ai')
.setDescription('— Ask to artificial intelligence anything in your mind!')
.setNameLocalizations({
tr: 'yapay-zekaya-sor',
it: "chiedi-all'intelligenza-artificiale",
'zh-CN': '问人工智能',
})
.setDescriptionLocalizations({
tr: '— Aklınızdaki her şeyi yapay zekaya sorun!',
it: "— Chiedi all'intelligenza artificiale qualsiasi cosa nella tua mente!",
'zh-CN': '— 向人工智能询问您的想法!',
})
.addStringOption((option) =>
option
.setName('text')
.setDescription('• So... What is it?')
.setRequired(true)
.setNameLocalizations({ tr: 'konu', it: 'soggetto', 'zh-CN': '主题' })
.setDescriptionLocalizations({
tr: '• Ehm... Ne soracaksın?',
'zh-CN': '• 嗯……你会问什么?',
it: '• Ehm... Cosa chiederai?',
}),
),
async execute({ interaction }) {
// Configuration of openai
const configuration = new Configuration({
apiKey: config.openai.apiKey,
organization: config.openai.organization,
});
const openai = new OpenAIApi(configuration);

// OpenAI
if (interaction.channel.id === '795473337697697837') {
if (interaction.author.bot) return;

try {
const completion = await openai.createCompletion({
model: 'text-davinci-003',
prompt: interaction.content,
temperature: 0.5,
max_tokens: 400,
top_p: 1.0,
frequency_penalty: 0.5,
presence_penalty: 0.0,
stop: ['You:'],
});

interaction.reply(`${completion.data.choices[0].text}`);
} catch (error) {
interaction.reply({
content: `Sorry, couldn't answer that. I don't want to...`,
ephemeral: true,
});
console.log(error);
}
}
},
};

0 comments on commit 13d1ffd

Please sign in to comment.