Add size option and response embed for dall-e

This commit is contained in:
Skylar Grant 2023-05-29 08:47:07 -04:00
parent 53625be91f
commit 4e2e8bc702
2 changed files with 25 additions and 4 deletions

View File

@ -377,6 +377,14 @@ const functions = {
interaction.reply({ embeds: [ strainEmbed ]});
},
dalle(prompt, imageUrl) {
const dalleEmbed = new Discord.MessageEmbed()
.setAuthor({ name: "NodDraw" })
.setTimestamp()
.setImage(imageUrl)
.setFooter({ text: prompt });
return { embeds: [dalleEmbed] };
}
},
collect: {
gifName(interaction) {
@ -561,11 +569,12 @@ const functions = {
resolve(response);
});
},
imagePrompt(userPrompt, userId) {
imagePrompt(userPrompt, size, userId) {
return new Promise(async (resolve, reject) => {
try {
const response = await openai.createImage({
prompt: userPrompt,
size: size,
user: userId
});
resolve(response.data.data[0].url);

View File

@ -9,13 +9,25 @@ module.exports = {
o.setName("prompt")
.setDescription("Prompt to send to DALL-e")
.setRequired(true)
),
)
.addStringOption(o =>
o.setName("size")
.setDescription("1024x1024, 512x512, 256x256")
.setRequired(false)
.addChoices(
{ name: "1024x1024 (2¢)", value: "1024x1024" },
{ name: "512x512 (1.8¢)", value: "512x512" },
{ name: "256x256 (1.6¢)", value: "256x256" }
)),
async execute(interaction) {
try {
await interaction.deferReply();
const userPrompt = interaction.options.getString("prompt");
const response = await fn.openAI.imagePrompt(userPrompt);
await interaction.editReply(`${response}`);
const size = interaction.options.getString("size") ? interaction.options.getString("size") : "512x512";
const imageUrl = await fn.openAI.imagePrompt(userPrompt, size);
const dalleEmbed = fn.embeds.dalle(userPrompt, imageUrl);
await interaction.editReply(dalleEmbed);
} catch (err) {
const errorId = fn.generateErrorId();
console.error(`${errorId}: ${err}`);