Implement logging to db
This commit is contained in:
parent
efdc605dc0
commit
200468ac10
@ -391,7 +391,7 @@ const functions = {
|
|||||||
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" })
|
||||||
.setDescription(`**Prompt**\n${prompt}\n\n**Response**\n${response}`)
|
.setDescription(`**Prompt**\n${prompt}\n\n**Response**\n${response}`)
|
||||||
.setFooter({ text: `This prompt used ${usage.tokens} tokens for a cost of ${usage.usd}¢` })
|
.setFooter({ text: `This prompt used ${usage.tokens} tokens for a cost of ${usage.usdc}¢` })
|
||||||
return { embeds: [gptEmbed] };
|
return { embeds: [gptEmbed] };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -488,6 +488,12 @@ const functions = {
|
|||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
openai(user, prompt, engine, tokens, usdc) {
|
||||||
|
const query = `INSERT INTO openai (user, prompt, engine, tokens, usdc) VALUES (${db.escape(user)}, ${db.escape(prompt)}, ${db.escape(engine)}, ${db.escape(tokens)}, ${db.escape(usdc)})`;
|
||||||
|
db.query(query, (err) => {
|
||||||
|
if (err) throw err;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
download: {
|
download: {
|
||||||
|
@ -17,9 +17,10 @@ module.exports = {
|
|||||||
const responseText = response.choices[0].text.slice(2);
|
const responseText = response.choices[0].text.slice(2);
|
||||||
const usage = {
|
const usage = {
|
||||||
tokens: response.usage.total_tokens,
|
tokens: response.usage.total_tokens,
|
||||||
usd: response.usage.total_tokens * ( 0.2 / 1000 ) // 0.2¢ per 1000 tokens or 0.0002¢ per token.
|
usdc: 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);
|
const gptEmbed = fn.embeds.gpt(userPrompt, responseText, usage);
|
||||||
await interaction.editReply(gptEmbed);
|
await interaction.editReply(gptEmbed);
|
||||||
|
fn.upload.openai(interaction.user.id, userPrompt, "gpt-3.5-turbo", usage.tokens, usage.usdc);
|
||||||
},
|
},
|
||||||
};
|
};
|
@ -1,5 +1,6 @@
|
|||||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||||
const fn = require('../functions.js');
|
const fn = require('../functions.js');
|
||||||
|
const strings = require("../strings.json");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
@ -28,6 +29,7 @@ module.exports = {
|
|||||||
const imageUrl = await fn.openAI.imagePrompt(userPrompt, size);
|
const imageUrl = await fn.openAI.imagePrompt(userPrompt, size);
|
||||||
const dalleEmbed = fn.embeds.dalle(userPrompt, imageUrl, size);
|
const dalleEmbed = fn.embeds.dalle(userPrompt, imageUrl, size);
|
||||||
await interaction.editReply(dalleEmbed);
|
await interaction.editReply(dalleEmbed);
|
||||||
|
fn.upload.openai(interaction.user.id, userPrompt, "dalle", 0, strings.costs.dalle[size]);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorId = fn.generateErrorId();
|
const errorId = fn.generateErrorId();
|
||||||
console.error(`${errorId}: ${err}`);
|
console.error(`${errorId}: ${err}`);
|
||||||
|
Loading…
Reference in New Issue
Block a user