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 ]}); 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: { collect: {
gifName(interaction) { gifName(interaction) {
@ -561,11 +569,12 @@ const functions = {
resolve(response); resolve(response);
}); });
}, },
imagePrompt(userPrompt, userId) { imagePrompt(userPrompt, size, userId) {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
const response = await openai.createImage({ const response = await openai.createImage({
prompt: userPrompt, prompt: userPrompt,
size: size,
user: userId user: userId
}); });
resolve(response.data.data[0].url); resolve(response.data.data[0].url);

View File

@ -9,13 +9,25 @@ module.exports = {
o.setName("prompt") o.setName("prompt")
.setDescription("Prompt to send to DALL-e") .setDescription("Prompt to send to DALL-e")
.setRequired(true) .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) { async execute(interaction) {
try { try {
await interaction.deferReply(); await interaction.deferReply();
const userPrompt = interaction.options.getString("prompt"); const userPrompt = interaction.options.getString("prompt");
const response = await fn.openAI.imagePrompt(userPrompt); const size = interaction.options.getString("size") ? interaction.options.getString("size") : "512x512";
await interaction.editReply(`${response}`);
const imageUrl = await fn.openAI.imagePrompt(userPrompt, size);
const dalleEmbed = fn.embeds.dalle(userPrompt, imageUrl);
await interaction.editReply(dalleEmbed);
} catch (err) { } catch (err) {
const errorId = fn.generateErrorId(); const errorId = fn.generateErrorId();
console.error(`${errorId}: ${err}`); console.error(`${errorId}: ${err}`);