From 36a0e6a872fea9565109bdcdc89dfe161e265fef Mon Sep 17 00:00:00 2001 From: Lukian LEIZOUR Date: Thu, 2 Mar 2023 20:18:22 +0100 Subject: [PATCH] commit --- app.js | 29 +++++++++++++++++++---------- libs/openAi.js | 1 - 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app.js b/app.js index b880122..6396685 100644 --- a/app.js +++ b/app.js @@ -154,17 +154,26 @@ client.on('interactionCreate', async interaction => { if (!interaction.isCommand()) return; if (interaction.commandName === 'gptrequest') { - answerQuestion(interaction.options.get('question').value).then((res) => { - const embed = new discord.EmbedBuilder() - .setColor(0xFABBDE) - .setAuthor({ name : "Reply to : " + interaction.member.user.username, iconURL : "https://cdn.discordapp.com/avatars/"+interaction.member.user.id+"/"+interaction.member.user.avatar+".jpeg"}) - .setTitle("Question : " + interaction.options.get('question').value) - .setDescription(res.data.choices[0].message.content) - .setFooter({ text : "Powered by OpenAI https://www.openai.com/", iconURL : "https://seeklogo.com/images/O/open-ai-logo-8B9BFEDC26-seeklogo.com.png" }); + interaction.deferReply(); - console.log('[Discord] Sent answer to : ' + interaction.options.get('question').value); - addToLogs('[Discord] Sent answer to : ' +interaction.options.get('question').value); - interaction.reply({ embeds : [embed] }); + answerQuestion(interaction.options.get('question').value).then((res) => { + if (res.data.choices[0].message.content.length > 4096) { + interaction.reply(res.data.choices[0].message.content.lenght); + addToLogs('[Discord] Sent answer to : ' +interaction.options.get('question').value); + console.log('[Discord] Sent answer to : ' + interaction.options.get('question').value); + } + else{ + const embed = new discord.EmbedBuilder() + .setColor(0xFABBDE) + .setAuthor({ name : "Reply to : " + interaction.member.user.username, iconURL : "https://cdn.discordapp.com/avatars/"+interaction.member.user.id+"/"+interaction.member.user.avatar+".jpeg"}) + .setTitle("Question : " + interaction.options.get('question').value) + .setDescription(res.data.choices[0].message.content) + .setFooter({ text : "Powered by OpenAI https://www.openai.com/", iconURL : "https://seeklogo.com/images/O/open-ai-logo-8B9BFEDC26-seeklogo.com.png" }); + + console.log('[Discord] Sent answer to : ' + interaction.options.get('question').value); + addToLogs('[Discord] Sent answer to : ' +interaction.options.get('question').value); + interaction.editReply({ embeds : [embed] }); + } }).catch((err) => { console.log(err); addToLogs(err); diff --git a/libs/openAi.js b/libs/openAi.js index 24bafc7..42d62e9 100644 --- a/libs/openAi.js +++ b/libs/openAi.js @@ -25,7 +25,6 @@ async function answerQuestion(query) { response = await openai.createChatCompletion({ model: "gpt-3.5-turbo", messages: [{ "role" : "user", "content" : query}], - max_tokens: 500, temperature: 0.9, }).catch((err) => { console.log(err);