This project enables you to deploy a Discord bot powered by OpenAI's GPT-3.5 model. It integrates with the chat models and offers features such as caching a configurable number of messages for each user and using newer chat endpoints.
- Customizable Persona: Through the
system_message.txt
, you can define the bot's behavior and personality. Want a cheerful assistant or a quirky know-it-all? You decide! - Configurable Role Permissions: Ensure that only specific roles can interact with the bot for controlled interactions.
- Dynamic Message Caching: Retains the context of the conversation, improving conversational flow.
- Model Flexibility: The bot, by default, uses the GPT-3.5 Turbo-16k model for a balance of cost efficiency and extended context. However, you have the freedom to choose other OpenAI models as per your preferences.
- Docker installed on your machine/server.
- An OpenAI API Key.
- A Discord Bot Token.
- Prepare
system_message.txt
Configuration: Create asystem_message.txt
file on your system. This file provides context to the bot about its behavior during conversations. Define the bot's persona or guidelines on how it should interact.
2a. Run the Docker Container:
docker run \
-e DISCORD_BOT_TOKEN="YOUR_DISCORD_BOT_TOKEN" \
-e OPENAI_API_KEY="YOUR_OPENAI_API_TOKEN" \
-e MAX_CACHE=NUMBER_OF_MESSAGES_TO_REMEMBER \
-e COOLDOWN_TIME=SECONDS_TO_WAIT_BEFORE_RESPONDING \
-e ROLE_ID="DISCORD_ROLE_ID_BOT_RESPONDS_TO" \
-e OPENAI_MODEL="MODEL_NAME" \
-v /path/to/your/system_message.txt:/openai-discord-chatbot/system_message.txt \
sauramello/openai-discord-chatbot
2b. Use Docker Compose:
version: '3.3'
services:
openai-discord-chatbot:
image: sauramello/openai-discord-chatbot
container_name: openai-discord
environment:
- DISCORD_BOT_TOKEN= #Your Discord bot's token (see: https://discord.com/developers/applications)
- OPENAI_API_KEY= #Your secret API key (see: https://platform.openai.com/account/api-keys)
- MAX_CACHE= #Number of messages to remember for context
- COOLDOWN_TIME= #Seconds to wait until the bot responds
- ROLE_ID= #The role ID that the bot will only respond to
- OPENAI_MODEL=gpt-3.5-turbo-16k #Default (see: https://platform.openai.com/docs/models)
volumes:
- '/directory/to/system_message.txt:/openai-discord-chatbot/system_message.txt'
The system_message.txt
file is crucial for informing the bot about its behavior, tone, and interaction style. While this message is not directly passed to the users, it provides context to the bot about how it should respond, behave, and interact during the conversation.
- Open the
system_message.txt
file in your preferred text editor. - Replace the existing text with instructions or context that you believe would shape the bot's behavior appropriately. For example, you can set the bot to be more formal, casual, or even role-play a specific character.
- Save the changes.
When deploying the bot within a Docker container, ensure that you pass the path to your system_message.txt
using the volume mounting option.
Remember, while the message in this file isn't shown to users, it directly influences the bot's tone, style, and manner of interaction. Carefully craft this to suit the desired bot persona!
This bot is specifically optimized for the gpt-3.5-turbo-16k
model due to its balance between performance and cost. However, you can configure it to use other OpenAI models such as:
gpt-3.5-turbo
gpt-4
gpt-4-32k
Remember that different models come with varying token limits, capabilities, and costs. Hence, it's essential to choose a model that aligns with the requirements of your bot interactions and your budget.
Credits to ChatGPT for the foundational code used in this project.