v3.2.2-dev Merged new fixed sbs and OpenAI deintegration #12

Merged
voidf1sh merged 11 commits from v3.2.2-dev into main 2024-06-15 02:24:17 +00:00
4 changed files with 24 additions and 26 deletions
Showing only changes of commit f995d9a643 - Show all commits

View File

@ -22,20 +22,8 @@ const Discord = require('discord.js');
const FuzzySearch = require('fuzzy-search'); const FuzzySearch = require('fuzzy-search');
// OpenAI // OpenAI
const { Configuration, OpenAIApi } = require("openai"); const OpenAI = require("openai");
const openai = new OpenAI();
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
async function openAIStatus(o) {
const response = await o.listModels();
const models = response.data.data;
models.forEach(e => {
console.log(`Model ID: ${e.id}`);
});
};
openAIStatus(openai);
// Various imports from other files // Various imports from other files
const config = require('./config.json'); const config = require('./config.json');
@ -379,9 +367,9 @@ const functions = {
}, },
gpt(prompt, response, usage) { 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.5", 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.usdc}¢` }) .setFooter({ text: `This prompt used ${usage.tokens} tokens for a cost of ${usage.usdc}¢. Generated using ${strings.ai.chatModel}` })
return { embeds: [gptEmbed] }; return { embeds: [gptEmbed] };
}, },
generatingResponse() { generatingResponse() {
@ -570,16 +558,17 @@ const functions = {
openAI: { openAI: {
chatPrompt(userPrompt) { chatPrompt(userPrompt) {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
const response = await openai.createCompletion({ const response = await openai.chat.completions.create({
model: 'text-davinci-003', messages: [{
prompt: userPrompt, role: 'user',
temperature: 0.7, content: userPrompt
max_tokens: 250 }],
model: strings.ai.chatModel
}).catch(e => { }).catch(e => {
reject(e); reject(e);
return null; return null;
}); });
resolve(response.data); resolve(response);
}); });
}, },
imagePrompt(userPrompt, size, userId) { imagePrompt(userPrompt, size, userId) {

View File

@ -12,7 +12,7 @@
"dotenv": "^10.0.0", "dotenv": "^10.0.0",
"fuzzy-search": "^3.2.1", "fuzzy-search": "^3.2.1",
"mysql": "^2.18.1", "mysql": "^2.18.1",
"openai": "^3.2.1", "openai": "^4.12.0",
"tenorjs": "^1.0.10" "tenorjs": "^1.0.10"
}, },
"engines": { "engines": {

View File

@ -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()
@ -15,13 +16,14 @@ module.exports = {
await interaction.editReply(fn.embeds.generatingResponse()); await interaction.editReply(fn.embeds.generatingResponse());
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 responseText = response.choices[0].text; const responseText = response.choices[0].message.content;
const usage = { const usage = {
tokens: response.usage.total_tokens, tokens: response.usage.total_tokens,
usdc: response.usage.total_tokens * ( 0.2 / 1000 ) // 0.2¢ per 1000 tokens or 0.0002¢ per token. 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); 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); fn.upload.openai(interaction.user.id, userPrompt, strings.ai.chatModel, usage.tokens, usage.usdc);
}, },
}; };

View File

@ -32,5 +32,12 @@
"1024x1024": 2.0 "1024x1024": 2.0
} }
}, },
"ai": {
"chatModel": "gpt-3.5-turbo",
"chatPromptCentsPer": 0.15,
"chatPromptUnits": 1000,
"chatResCentsPer": 0.2,
"chatResUnits": 1000
},
"temp": {} "temp": {}
} }