Adding costs to embeds
This commit is contained in:
parent
2c75ff09d9
commit
efdc605dc0
17
functions.js
17
functions.js
@ -377,26 +377,21 @@ const functions = {
|
|||||||
|
|
||||||
interaction.reply({ embeds: [ strainEmbed ]});
|
interaction.reply({ embeds: [ strainEmbed ]});
|
||||||
},
|
},
|
||||||
dalle(user, prompt, imageUrl) {
|
dalle(prompt, imageUrl, size) {
|
||||||
const dalleEmbed = new Discord.MessageEmbed()
|
const dalleEmbed = new Discord.MessageEmbed()
|
||||||
.setAuthor({ name: "NodBot powered by DALL-E", iconURL: "https://assets.vfsh.dev/openai-logos/PNGs/openai-logomark.png" })
|
.setAuthor({ name: "NodBot powered by DALL-E", iconURL: "https://assets.vfsh.dev/openai-logos/PNGs/openai-logomark.png" })
|
||||||
.addFields(
|
.addFields(
|
||||||
{ name: "Prompt", value: prompt }
|
{ name: "Prompt", value: prompt }
|
||||||
)
|
)
|
||||||
.setImage(imageUrl)
|
.setImage(imageUrl)
|
||||||
.setFooter({ text: user.username, iconURL: user.avatarURL() })
|
.setFooter({ text: `This ${size} image cost ${strings.costs.dalle[size]}¢ to generate.` })
|
||||||
.setTimestamp();
|
|
||||||
return { embeds: [dalleEmbed] };
|
return { embeds: [dalleEmbed] };
|
||||||
},
|
},
|
||||||
gpt(user, prompt, response) {
|
gpt(prompt, response, usage) {
|
||||||
const gptEmbed = new Discord.MessageEmbed()
|
const gptEmbed = new Discord.MessageEmbed()
|
||||||
.setAuthor({ name: "NodBot powered by GPT-3", iconURL: "https://assets.vfsh.dev/openai-logos/PNGs/openai-logomark.png" })
|
.setAuthor({ name: "NodBot powered by GPT-3", iconURL: "https://assets.vfsh.dev/openai-logos/PNGs/openai-logomark.png" })
|
||||||
.addFields(
|
.setDescription(`**Prompt**\n${prompt}\n\n**Response**\n${response}`)
|
||||||
{ name: "Prompt", value: prompt },
|
.setFooter({ text: `This prompt used ${usage.tokens} tokens for a cost of ${usage.usd}¢` })
|
||||||
{ name: "Response", value: response }
|
|
||||||
)
|
|
||||||
.setFooter({ text: user.username, iconURL: user.avatarURL() })
|
|
||||||
.setTimestamp();
|
|
||||||
return { embeds: [gptEmbed] };
|
return { embeds: [gptEmbed] };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -580,7 +575,7 @@ const functions = {
|
|||||||
reject(e);
|
reject(e);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
resolve(response.data.choices[0].text);
|
resolve(response.data);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
imagePrompt(userPrompt, size, userId) {
|
imagePrompt(userPrompt, size, userId) {
|
||||||
|
@ -14,7 +14,12 @@ module.exports = {
|
|||||||
await interaction.deferReply();
|
await interaction.deferReply();
|
||||||
const userPrompt = interaction.options.getString("prompt");
|
const userPrompt = interaction.options.getString("prompt");
|
||||||
const response = await fn.openAI.chatPrompt(userPrompt).catch(e => console.error(e));
|
const response = await fn.openAI.chatPrompt(userPrompt).catch(e => console.error(e));
|
||||||
const gptEmbed = fn.embeds.gpt(interaction.user, userPrompt, response);
|
const responseText = response.choices[0].text.slice(2);
|
||||||
|
const usage = {
|
||||||
|
tokens: response.usage.total_tokens,
|
||||||
|
usd: response.usage.total_tokens * ( 0.2 / 1000 ) // 0.2¢ per 1000 tokens or 0.0002¢ per token.
|
||||||
|
};
|
||||||
|
const gptEmbed = fn.embeds.gpt(userPrompt, responseText, usage);
|
||||||
await interaction.editReply(gptEmbed);
|
await interaction.editReply(gptEmbed);
|
||||||
},
|
},
|
||||||
};
|
};
|
@ -26,7 +26,7 @@ module.exports = {
|
|||||||
const size = interaction.options.getString("size") ? interaction.options.getString("size") : "512x512";
|
const size = interaction.options.getString("size") ? interaction.options.getString("size") : "512x512";
|
||||||
|
|
||||||
const imageUrl = await fn.openAI.imagePrompt(userPrompt, size);
|
const imageUrl = await fn.openAI.imagePrompt(userPrompt, size);
|
||||||
const dalleEmbed = fn.embeds.dalle(interaction.user, userPrompt, imageUrl);
|
const dalleEmbed = fn.embeds.dalle(userPrompt, imageUrl, size);
|
||||||
await interaction.editReply(dalleEmbed);
|
await interaction.editReply(dalleEmbed);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorId = fn.generateErrorId();
|
const errorId = fn.generateErrorId();
|
||||||
|
10
strings.json
10
strings.json
@ -22,5 +22,15 @@
|
|||||||
"bussin fr, no cap",
|
"bussin fr, no cap",
|
||||||
"ongggg no :billed_cap: fr fr"
|
"ongggg no :billed_cap: fr fr"
|
||||||
],
|
],
|
||||||
|
"costs": {
|
||||||
|
"gpt": {
|
||||||
|
"gpt-3.5-turbo": 0.2
|
||||||
|
},
|
||||||
|
"dalle": {
|
||||||
|
"256x256": 1.6,
|
||||||
|
"512x512": 1.8,
|
||||||
|
"1024x1024": 2.0
|
||||||
|
}
|
||||||
|
},
|
||||||
"temp": {}
|
"temp": {}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user