This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 842312e
Showing
7 changed files
with
551 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
DISCORD_TOKEN= | ||
OPENAI_ORG= | ||
OPENAI_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
.env | ||
|
||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
16.18.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# PFA Discord Bot GPT (TODO) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require('dotenv').config(); | ||
|
||
const { Client, GatewayIntentBits } = require('discord.js'); | ||
const client = new Client({ intents:[ | ||
GatewayIntentBits.Guilds, | ||
GatewayIntentBits.GuildMessages, | ||
GatewayIntentBits.MessageContent | ||
]}) | ||
|
||
const {Configuration, OpenAIApi} = require('openai'); | ||
const configuration = new Configuration({ | ||
organization: process.env.OPENAI_ORG, | ||
apiKey: process.env.OPENAI_KEY, | ||
}) | ||
|
||
const openai = new OpenAIApi(configuration); | ||
const chatbotName = "Enetti"; | ||
|
||
let prompt =`${chatbotName} is a friendly chatbot that represent National School of Electronics and Telecommunications of Sfax. \n\ | ||
You: Hello! \n\ | ||
${chatbotName}: Hello, how are you today?\n\ | ||
You: Fine thanks for asking :), What is EnetCom? \n\ | ||
${chatbotName}: Sure, EnetCom or Enet'Com are shortnames for National School of Electronics and Telecommunications of Sfax iin French.\n\ | ||
You: Ah okay, can you tell me more about it?\n\ | ||
${chatbotName}: Absolutly, The National School of Electronics and Telecommunications of Sfax is a public establishment at the Technopôle de Sfax.\n\ | ||
ENET'Com belongs to the University of Sfax and the Ministry of Higher Education and Scientific Research (MESRS).\n\ | ||
You: How many departements do EnetCom have?\n\ | ||
${chatbotName}: it have four departments that include all the members of the teaching and research staff in the establishment belonging to the bodies of higher education and all other individuals or organizations practicing in one of the disciplines taught. The departments are : Electronic, Industrial Computing, Telecommunications and Mathematics and Decisional Systems\n`; | ||
|
||
const stops = new Set() | ||
stops.add(`${chatbotName}:`); | ||
stops.add("You:"); | ||
|
||
// | ||
client.on('ready', () => { | ||
console.log(`Logged in as ${client.user.tag}!`); | ||
}); | ||
|
||
client.login(process.env.DISCORD_TOKEN); | ||
|
||
client.on('messageCreate', function(message){ | ||
if(message.author.bot) return; | ||
console.log(`${message.author.username} has created a message!`); | ||
prompt += `You: ${message.content}\n\ | ||
${chatbotName}:`; | ||
/* stops.add(`${message.author.username}:`); */ | ||
|
||
(async () => { | ||
const getResponse = await openai.createCompletion({ | ||
model: "text-davinci-003", | ||
prompt: prompt, | ||
temperature: 0.9, | ||
max_tokens: 100, | ||
stop: Array.from(stops) | ||
}); | ||
|
||
message.reply(`${getResponse.data.choices[0].text}`); | ||
console.log(`I've replied to ${message.author.username}!`); | ||
prompt += `${getResponse.data.choices[0].text}\n`; | ||
return; | ||
})(); | ||
}) |
Oops, something went wrong.
842312e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Close #2