Implemented ChatGPT functionality

This commit is contained in:
Logan Cusano
2023-02-26 14:28:57 -05:00
parent c605074d05
commit 77a3c5c6fc
3 changed files with 44 additions and 38 deletions

View File

@@ -31,10 +31,26 @@ module.exports = {
defaultTokenUsage: 100,
deferInitialReply: true,
async execute(interaction) {
const promptText = interaction.options.getString('prompt');
const temperature = interaction.options.getNumber('temperature') ?? undefined;
const maxTokens = interaction.options.getNumber('tokens') ?? undefined;
const discordAccountId = interaction.member.id;
try {
submitPromptTransaction(interaction, async (err, result) => {
submitPromptTransaction(promptText, temperature, maxTokens, discordAccountId, async (err, result) => {
if (err) throw err;
await interaction.editReply({ content: `${interaction.member.user} ${result.promptResult}`, ephemeral: false });
const gptEmbed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle(`New GPT response`)
.setDescription(`${interaction.member.user} sent: '${promptText}'`)
.addFields(
{ name: 'Generated Text', value: result.promptResult },
)
.addFields({ name: 'Tokens Used', value: `${result.totalTokens}`, inline: true })
.setTimestamp()
.setFooter({ text: 'Brought to you by Emmelia.' });
await interaction.editReply({ embeds: [gptEmbed], ephemeral: false });
});
// Needs reply code to reply to the generation