-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes on generate image and now there's text ai.
- Loading branch information
Neodevils
committed
Feb 18, 2023
1 parent
cbb9ae6
commit 13d1ffd
Showing
2 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
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); | ||
} | ||
} | ||
}, | ||
}; |