First basic implementation of ChatGPT
This commit is contained in:
parent
57238ce57a
commit
755c8510d7
24
functions.js
24
functions.js
@ -21,6 +21,14 @@ const Discord = require('discord.js');
|
|||||||
// Fuzzy text matching for db lookups
|
// Fuzzy text matching for db lookups
|
||||||
const FuzzySearch = require('fuzzy-search');
|
const FuzzySearch = require('fuzzy-search');
|
||||||
|
|
||||||
|
// OpenAI
|
||||||
|
const { Configuration, OpenAIApi } = require("openai");
|
||||||
|
|
||||||
|
const configuration = new Configuration({
|
||||||
|
apiKey: process.env.OPENAI_API_KEY,
|
||||||
|
});
|
||||||
|
const openai = new OpenAIApi(configuration);
|
||||||
|
|
||||||
// Various imports from other files
|
// Various imports from other files
|
||||||
const config = require('./config.json');
|
const config = require('./config.json');
|
||||||
const strings = require('./strings.json');
|
const strings = require('./strings.json');
|
||||||
@ -530,6 +538,22 @@ const functions = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
openAI: {
|
||||||
|
chatPrompt(userPrompt) {
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
|
const response = await openai.createCompletion({
|
||||||
|
model: 'text-davinci-003',
|
||||||
|
prompt: userPrompt,
|
||||||
|
temperature: 0,
|
||||||
|
max_tokens: 250
|
||||||
|
}).catch(e => {
|
||||||
|
reject(e);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
resolve(response);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
// Parent-Level functions (miscellaneuous)
|
// Parent-Level functions (miscellaneuous)
|
||||||
closeRequest(requestId, interaction) {
|
closeRequest(requestId, interaction) {
|
||||||
if (interaction.user.id == ownerId) {
|
if (interaction.user.id == ownerId) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "nodbot",
|
"name": "nodbot",
|
||||||
"version": "3.1.0",
|
"version": "3.2.0",
|
||||||
"description": "Nods and Nod Accessories.",
|
"description": "Nods and Nod Accessories, now with ChatGPT!",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/builders": "^0.16.0",
|
"@discordjs/builders": "^0.16.0",
|
||||||
@ -12,10 +12,11 @@
|
|||||||
"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",
|
||||||
"tenorjs": "^1.0.10"
|
"tenorjs": "^1.0.10"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "16.x"
|
"node": "18.x"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^7.32.0"
|
"eslint": "^7.32.0"
|
||||||
|
20
slash-commands/chat.js
Normal file
20
slash-commands/chat.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||||
|
const fn = require('../functions.js');
|
||||||
|
|
||||||
|
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();
|
||||||
|
const userPrompt = interaction.options.getString("prompt");
|
||||||
|
const response = await fn.openAI.chatPrompt(userPrompt).catch(e => console.error(e));
|
||||||
|
const responseText = response.data.choices[0].text;
|
||||||
|
await interaction.editReply(`${responseText}`);
|
||||||
|
},
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user