Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

GPT2 Chatbot

Bridge between GPT2 models and the Discord chat platform · By IchorDrops

Setup Instructions Sticky

A topic by IchorDrops created Feb 03, 2023 Views: 266 Replies: 3
Viewing posts 1 to 4
Developer (2 edits)

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: "
(3 edits)

windows build seemingly doesnt check for the dlls in the lib folder, errors trying to find  torch_cpu.dll and c10.dll

out of curiosity i just threw them into the main directory

thread 'main' panicked at 'The `framework`-feature is enabled (it's on by default), but no framework was provided.
If you don't want to use the command framework, disable default features and specify all features you want to use.', C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\serenity-0.11.5\src\client\mod.rs:360:29
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

gonna try it on linux later


edit:

directory structure works in linux, however it gets the same error as above regarding framework

thread 'main' panicked at 'The `framework`-feature is enabled (it's on by default), but no framework was provided.
If you don't want to use the command framework, disable default features and specify all features you want to use.', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/serenity-0.11.5/src/client/mod.rs:360:29
stack backtrace:
   0: rust_begin_unwind
             at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/core/src/panicking.rs:65:14
   2: core::panicking::panic_display
             at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/core/src/panicking.rs:139:5
   3: core::panicking::panic_str
             at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/core/src/panicking.rs:123:5
   4: core::option::expect_failed
             at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/core/src/option.rs:1879:5
   5: <serenity::client::ClientBuilder as core::future::future::Future>::poll
   6: gptbot::main::{{closure}}
   7: tokio::runtime::context::BlockingRegionGuard::block_on
   8: tokio::runtime::scheduler::multi_thread::MultiThread::block_on
   9: tokio::runtime::runtime::Runtime::block_on
  10: gptbot::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Developer

Interesting! Looks like I forgot some configuration in the release build. And apparently it’s not possible to set the executable to look in a specific path for libraries either, but they will search the same path that they’re in for them. So that’s an easy enough workaround.

An update to address these problems (and much more) is coming soon.

Developer

A new version has been pushed, and the instructions have been updated.