61 lines
2.3 KiB
JavaScript
61 lines
2.3 KiB
JavaScript
const { submitTextPromptTransaction } = require("../controllers/openAiController");
|
|
const { SlashCommandBuilder } = require('discord.js');
|
|
const { DebugBuilder } = require("../utilities/debugBuilder");
|
|
const log = new DebugBuilder("server", "chat");
|
|
const { EmmeliaEmbedBuilder } = require('../libUtils');
|
|
|
|
const COST_OF_COMMAND = 100
|
|
|
|
module.exports = {
|
|
data: new SlashCommandBuilder()
|
|
.setName('chat')
|
|
.setDescription(`Send a text prompt to ChatGPT`)
|
|
.addStringOption(option =>
|
|
option.setName('prompt')
|
|
.setDescription('The prompt to be sent to ChatGPT')
|
|
.setRequired(true))
|
|
.addBooleanOption(option =>
|
|
option.setName('public')
|
|
.setDescription("Set this to false if you would like the message to only be visible to you. *defaults to public*")
|
|
.setRequired(false))
|
|
.addNumberOption(option =>
|
|
option.setName('temperature')
|
|
.setDescription('Set the temperature, 0 = repetitive, 1 = random; Defaults to 0')
|
|
.setRequired(false))
|
|
.addNumberOption(option =>
|
|
option.setName('tokens')
|
|
.setDescription(`The max amount of tokens to be spent, defaults to ${COST_OF_COMMAND}`)
|
|
.setRequired(false)),
|
|
example: "chat [tell me a story] [0.07] [400]", // Need to figure out the tokens
|
|
isPrivileged: false,
|
|
requiresTokens: true,
|
|
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 {
|
|
submitTextPromptTransaction(promptText, temperature, maxTokens, discordAccountId, interaction, this, async (err, result) => {
|
|
if (err) throw err;
|
|
|
|
const gptEmbed = new EmmeliaEmbedBuilder()
|
|
.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 })
|
|
|
|
await interaction.editReply({ embeds: [gptEmbed], ephemeral: false });
|
|
});
|
|
|
|
// Needs reply code to reply to the generation
|
|
}catch(err){
|
|
log.ERROR(err)
|
|
//await interaction.reply(err.toString());
|
|
}
|
|
}
|
|
}; |