Provides access to OpenAI models via a Discord bot.
A Python Discord bot which provides access to OpenAI's GPT3. Inspired by @Zero6992's chatGPT-discord-bot repository. Provides the modifications:
- Major components rewritten
- Using PyCord instead of DiscordPy
- Env vars used for configuration
- Python virtual environment
- Docker development setup
- Features added
- History between bot and users saved in Redis
- Provides a transcript of the bot's conversation as part of the GPT3 prompt so the model appears to "remember" a portion of the conversation
Configuration values are set via the following environment variables:
OPENAI_API_KEY
: Your OpenAPI API key- Redis
REDIS_HOST
: Hostname of Redis server (Default:redis
)REDIS_PORT
: Port number of Redis server (Default:6379
)REDIS_DB
: Database number of Redis server (Default:0
)
- Discord
DISCORD_GUILD_ID
: ID of Discord server in which Bot will runDISCORD_BOT_TOKEN
: API token for Discord botDISCORD_CHANNEL_ID
: If provided then the bot will only interact in the provided channel
Pipenv is used to manage a Python virtual environment. Install dependencies and then activate the environment:
pipenv install
pipenv shell
Then run the bot:
python ./main.py
The Dockerfile
in the repository root performs these steps automatically. The docker-compose-prod.yaml
file runs this Docker image.
The docker-compose.yaml
and dev.Dockerfile
files provide a development environment which is pre-setup. To use:
- Make a copy of
dev-example.env
nameddev.env
and fill in your own values - Launch the Docker Compose stack:
docker compose up -d --build
- Build the Docker image:
docker build -t noahhuppert/chatgpt-discord-bot:vx.y.z
- Push the Docker image
docker push noahhuppert/chatgpt-discord-bot:vx.y.z
- Create a new GitHub Release
- Include a short description of the changes
- Include the Docker image tag by writing:
Docker image: `noahhuppert/chatgpt-discord-bot:vx.y.z`