GPT2 Discord Bot
Usage
Preparation (API)
Log into the Discord Developer Portal and create a new application for your bot. Copy the Application ID
field for a later step.
Within the newly created application, proceed to the Bot
tab and create a new bot. Copy the Token
field for a later step.
Disable Public Bot
and enable Message Content Intent
.
Use the following link to add your bot to a server which you have permissions to add integrations to.
https://discord.com/api/oauth2/authorize?client_id=APPLICATION_ID_HERE&permissions=414464665664&scope=bot
Replace APPLICATION_ID_HERE
with your previously copied Application ID
Preparation (Local)
Create a file named .env
and insert the following into it
DISCORD_TOKEN=
Add the Token
you previously copied in the API section of these instructions after the equals sign.
Create a folder named brain
in the same folder as the gptbot executable and copy rust_model.ot
and config.json
into it from a brain package provided on the itch.io page for this project.
Windows
Download this PyTorch C++ Library and copy everything from the lib directory inside of it over to same directory that gptbot.exe exists in.
Linux
Create a folder named lib
in the same folder as the gptbot executable
Download this PyTorch C++ Library for Linux and copy everything from the lib directory inside of it over to the lib directory you created.
Depending on your system you may also have to install libgomp
using your package manager.
Running the Bot
Run the bot, and once it is online proceed to the channel that you want the bot to interact in. Send ~register
and then click the button that says ‘Register in guild’. This will make all of the configuration slash commands available.
Use the /enable
command to have the bot begin responding in the channel you use this command in. There are various other commands that you can use to further tune the bot for your usecase, and each of them save according to the channel that they are used in as well, allowing you to provide different experiences in different channels.
NOTE: The commands are all undocumented at this time, this will improve in future updates. NOTE: You will see GPT3-related commands as well, this feature does not yet work.
You can further tune how the GPT2 model responds by using the /set_context
command. It will act as additional context added to every text generation. For example, you can make the bot respond to questions rather than simply completing a prompt by adding the following
Q: {{TEXT}}
A:
{{TEXT}}
is a special token that will be replaced with what a user has sent through discord before being passed through the GPT2 model.
NOTE: The provided context must be wrapped in quotes if it has newlines, and you must use the ~ prefixed version of the command rather than the slash command. Example:
~set_context "Q: {{TEXT}}
A: "