nodbot/slash-commands/chat.js
Skylar Grant f995d9a643
Some checks failed
NodBot Production Dockerization / build (pull_request) Failing after 10m32s
Upgrade to gpt-3.5-turbo
2023-10-18 17:33:03 -04:00

29 lines
1.2 KiB
JavaScript

const { SlashCommandBuilder } = require('@discordjs/builders');
const fn = require('../functions.js');
const strings = require('../strings.json');
module.exports = {
data: new SlashCommandBuilder()
.setName('chat')
.setDescription('Send a message to ChatGPT')
.addStringOption(o =>
o.setName("prompt")
.setDescription("Prompt to send to ChatGPT")
.setRequired(true)
),
async execute(interaction) {
await interaction.deferReply();
await interaction.editReply(fn.embeds.generatingResponse());
const userPrompt = interaction.options.getString("prompt");
const response = await fn.openAI.chatPrompt(userPrompt).catch(e => console.error(e));
const responseText = response.choices[0].message.content;
const usage = {
tokens: response.usage.total_tokens,
usdc: (response.usage.prompt_tokens * (strings.ai.chatPromptCentsPer / strings.ai.chatPromptUnits)) +
(response.usage.completion_tokens * (strings.ai.chatResCentsPer / strings.ai.chatResUnits))
};
const gptEmbed = fn.embeds.gpt(userPrompt, responseText, usage);
await interaction.editReply(gptEmbed);
fn.upload.openai(interaction.user.id, userPrompt, strings.ai.chatModel, usage.tokens, usage.usdc);
},
};