Adding Docker Support and updating README.md

This commit is contained in:
Josh Knapp 2024-12-19 17:53:34 -08:00
parent 1d8572e12b
commit 059dbd307f
3 changed files with 37 additions and 34 deletions

20
Dockerfile Normal file
View File

@ -0,0 +1,20 @@
# Use Python 3 base image
FROM python:3.9-slim
# Set working directory
WORKDIR /app
# Install system dependencies for audio support
RUN apt-get update && apt-get install -y \
python3-pip \
libopus0 \
&& rm -rf /var/lib/apt/lists/*
# Install required packages
RUN pip install --no-cache-dir discord.py python-dotenv openai
# Copy the bot script
COPY /scripts/discordbot.py .
# Run the bot on container start
CMD ["python", "discordbot.py"]

View File

@ -1,40 +1,23 @@
# OpenWebUI-Discordbot
A Discord bot to communicate with an OpenWebUI instance.
A Discord bot that interfaces with an OpenWebUI instance to provide AI-powered responses in your Discord server.
A helpful guide to creating your Discord Bot's Token: https://www.writebots.com/discord-bot-token/
Before running you will need to install the required modules
```
pip install discord.py python-dotenv openai
```
This script:
Uses environment variables for secure configuration
Initializes a Discord bot with message content intents
Configures the OpenAI client to point to your OpenWebUI instance
Watches for messages that mention the bot
When mentioned, it:
Removes the mention from the message to get the actual prompt
Shows a typing indicator while processing
Sends the prompt to OpenWebUI
Handles long responses by splitting them if necessary
Posts the response back to the Discord channel
To use this bot:
Create a Discord application and bot at the Discord Developer Portal
Get your bot token and add it to the .env file
Invite the bot to your server with appropriate permissions
Set up your OpenWebUI instance and get its API endpoint
Run the script
You can mention the bot in any channel it has access to with a message like:
@YourBot What is the weather like today?
The bot will process the message and respond with the AI-generated response from your OpenWebUI instance.
## Prerequisites
- Docker (for containerized deployment)
- Python 3.8 or higher+ (for local development)
- A Discord Bot Token ([How to create a Discord Bot Token](https://www.writebots.com/discord-bot-token/))
- Access to an OpenWebUI instance
## Installation
##### Running locally
1. Clone the repository
2. Copy `.env.sample` to `.env` and configure your environment variables:
```env
DISCORD_TOKEN=your_discord_bot_token
OPENAI_API_KEY=your_openwebui_api_key
OPENWEBUI_API_BASE=http://your_openwebui_instance:port/api
MODEL_NAME=your_model_name
```

View File

@ -1,4 +1,4 @@
DISCORD_TOKEN=your_discord_bot_token
OPENAI_API_KEY=your_openwebui_api_key
OPENWEBUI_API_BASE=http://your_openwebui_instance:port/v1
OPENWEBUI_API_BASE=http://your_openwebui_instance:port/api
MODEL_NAME="Your_Model_Name"