OpenAI GPT, driven by Discord
Project description
Persona Forge Discord (PFDiscord)
The basic goal of this project is to create a bridge between a Discord Bot and a Large Langage Model (LLM), like ChatGPT. The interface stems from TeLLMgramBot, but for Discord.
- To use this library, you must have a Discord account. If you don't have one, create one online.
- To set up a new Discord bot with "Manage Server" permissions, see this HowToGeek link.
- This requires priveliged message intents, which can be enabled in the Discord Developer Portal under Bot Settings.
Discord Bot + LLM Encapsulation
- The Discord interface handles special commands, especially on some basic "chatty" prompts and responses that don't require LLM like "Hello".
- Tokens are used to measure the length of all conversation messages between the Discord bot assistant and the user. This is useful to:
- Ensure the length does not go over the ChatGPT model limit. If it does, prune oldest messages to fit within the limit.
- Remember 50% of the past conversations when starting up PFDiscord again.
- Users can also clear their conversation history for privacy.
- A URL in [square brackets] can be mentioned for interpretation.
- Example: "What do you think of this article? [https://some_site/article]"
- This uses another ChatGPT model, preferrably GPT-4, to support more URL content by OpenAI tokens.
Directories
When initializing PFDiscord, the following directories get created:
configs- Contains bot conifguration files.config.yaml(can be a different name)- This file sets parameters for the Discord bot (its user name is given by API) and OpenAI's ChatGPT to process.
- The parameter
url_modelis to read URL content, different thanchat_modelthat the bot normally uses to interact with the user. - An empty
token_limitwould do the maximum amount of tokens supported by thechat_model(e.g. 4097 forgpt-3.5-turbo).
tokenGPT.yaml- This important YAML file contains token size parameters for every ChatGPT model possible supported by OpenAI.
- If the first time, only
gpt-3.5-turboandgpt-4get populated, but the user can specify more models with token size parameters as needed.
prompts- Contains prompt files for how the bot interacts with any user.test_personality.prmpt- This is a sample prompt file as a basis to test this library.
- The user can create more prompt files as needed for different personalities. See OpenAI Playground to test some ideas.
url_analysis.prmpt- This is a crucial prompt file to analysis URL content in brackets
[]in a different ChatGPT model (likelygpt-4or higher).
- This is a crucial prompt file to analysis URL content in brackets
errorlogs- Contains error log files to investigate if there are problems during the interaction.
- User will also get notified to contact the owner.
sessionlogs- Every conversation is stored between the Discord bot assistant and each user.
- If a user types
!forget, any session log files between the bot and the user will all be removed.
API Keys
Three API keys are required for operation:
- OpenAI - Drives the actual GPT AI.
- Discord - Found by creating a new bot application.
- VirusTotal - Performs safety checks on URLs.
There are two ways to populate each API key: environment variables or .key files.
Environment Variables
PFDiscord uses the following environment variables that can be pre-loaded with the three API keys respectively:
PFDISCORD_OPENAI_API_KEYPFDISCORD_DISCORD_API_KEYPFDISCORD_VIRUSTOTAL_API_KEY
During spin-up time, a user can call out os.environ[env_var] to set those variables, like the following example:
my_keys = Some_Vault_Fetch_Function()
os.environ['PFDISCORD_OPENAI_API_KEY'] = my_keys['GPTKey']
os.environ['PFDISCORD_DISCORD_API_KEY'] = my_keys['DiscordApplicationToken']
os.environ['PFDISCORD_VIRUSTOTAL_API_KEY'] = my_keys['VirusTotalToken']
This means the user can implement whatever key vault they want to fetch the keys at runtime, without needing key files.
API Key Files
By default, three files are created for the user to input each API key, unless its respective environment variable is defined already as discussed before:
openai.keydiscord.keyvirustotal.key
Bot Setup
This library includes an example script test_local.py, which uses files from the folders configs and prompts to process.
- Ensure the previous sections are followed with the proper API keys and your Discord bot set.
- Install this library via PIP (
pip install PFDiscord) and then import into your project. - Instantiate the bot by passing in various configuration pieces needed below:
discord_bot = PFDiscord.PFDiscord( bot_owner = <Bot owner's Discord username>, bot_nickname = <Bot nickname like 'Botty'>, chat_model = <Conversation ChatGPT model like 'gpt-3.5-turbo'>, url_model = <URL contents ChatGPT model like 'gpt-4'>, token_limit = <Maximum token count set, by default chat_model max>, persona_temp = <LLM factual to creative value [0-2], by default 1.0>, persona_prompt = <System prompt summarizing bot personality> ) - Turn on PFDiscord by calling:
discord_bot.run_bot() - Typing
!helpshows all available commands. - Only as owner, type
!startdirectly to the bot to initiate user conversations.
Resources
- See documentation from discord.py for the Discord API.
- For more information on ChatGPT models like
gpt-3.5-turboand tokens, see the following: - OpenAI Playground is a great place to test out prompts and responses.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file PFDiscord-1.0.5.tar.gz.
File metadata
- Download URL: PFDiscord-1.0.5.tar.gz
- Upload date:
- Size: 29.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ead1812075836463732c753824ec649ae79c65cfcf4551e6fec4848187e0f228
|
|
| MD5 |
f5763208da44c4f19426f1b07c2a4f0c
|
|
| BLAKE2b-256 |
bc6b7b8824c31980535b25724156be74086281262cdb36948ef89604555cdaa5
|
File details
Details for the file PFDiscord-1.0.5-py3-none-any.whl.
File metadata
- Download URL: PFDiscord-1.0.5-py3-none-any.whl
- Upload date:
- Size: 32.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82ec0fdc8b8beb105764c0729453c01dbb1652d2180ecd50d038debe0d0e21c6
|
|
| MD5 |
f6f7fe8baf24c5a21ce6a65a3d37da48
|
|
| BLAKE2b-256 |
95858cfc79c2b77bb2b4fdf92185b01909a21c9afe37f9d4ab80b6e1517ab024
|