Adding costs to embeds

This commit is contained in:
Skylar Grant 2023-05-31 08:07:12 -04:00
parent 2c75ff09d9
commit efdc605dc0
4 changed files with 23 additions and 13 deletions

View File

@ -377,26 +377,21 @@ const functions = {
interaction.reply({ embeds: [ strainEmbed ]});
},
dalle(user, prompt, imageUrl) {
dalle(prompt, imageUrl, size) {
const dalleEmbed = new Discord.MessageEmbed()
.setAuthor({ name: "NodBot powered by DALL-E", iconURL: "https://assets.vfsh.dev/openai-logos/PNGs/openai-logomark.png" })
.addFields(
{ name: "Prompt", value: prompt }
)
.setImage(imageUrl)
.setFooter({ text: user.username, iconURL: user.avatarURL() })
.setTimestamp();
.setFooter({ text: `This ${size} image cost ${strings.costs.dalle[size]}¢ to generate.` })
return { embeds: [dalleEmbed] };
},
gpt(user, prompt, response) {
gpt(prompt, response, usage) {
const gptEmbed = new Discord.MessageEmbed()
.setAuthor({ name: "NodBot powered by GPT-3", iconURL: "https://assets.vfsh.dev/openai-logos/PNGs/openai-logomark.png" })
.addFields(
{ name: "Prompt", value: prompt },
{ name: "Response", value: response }
)
.setFooter({ text: user.username, iconURL: user.avatarURL() })
.setTimestamp();
.setDescription(`**Prompt**\n${prompt}\n\n**Response**\n${response}`)
.setFooter({ text: `This prompt used ${usage.tokens} tokens for a cost of ${usage.usd}¢` })
return { embeds: [gptEmbed] };
}
},
@ -580,7 +575,7 @@ const functions = {
reject(e);
return null;
});
resolve(response.data.choices[0].text);
resolve(response.data);
});
},
imagePrompt(userPrompt, size, userId) {

View File

@ -14,7 +14,12 @@ module.exports = {
await interaction.deferReply();
const userPrompt = interaction.options.getString("prompt");
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);
},
};

View File

@ -26,7 +26,7 @@ module.exports = {
const size = interaction.options.getString("size") ? interaction.options.getString("size") : "512x512";
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);
} catch (err) {
const errorId = fn.generateErrorId();

View File

@ -22,5 +22,15 @@
"bussin fr, no cap",
"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": {}
}