This repository provides a Twitch chatbot that leverages the OpenAI API.
- OpenAI API Token: Sign up on their platform here
- Twitch Token: Login with your Twitch account and generate a token here
- Python 3.10 (includes
switch
-case
instruction)
You need to create an .env
file at the same level as the .main
file that contains these variables:
Variable | Value | Description |
---|---|---|
GPT_ENDPOINT | https://api.openai.com/v1/chat/completions | OpenAI API endpoint |
GPT_TOKEN | Bearer xx | Token for your registered OpenAI account |
TWITCH_IRC_SERVER | irc.chat.twitch.tv | Twitch IRC URL |
TWITCH_IRC_PORT | 6667 | Twitch IRC port |
TWITCH_IRC_NICKNAME | xx | Nickname of the account used as a bot |
TWITCH_TOKEN | oauth:xx | Token for the account used as a bot |
CHANNEL_MONITORING | #xx | Name of the channel to monitor, preceded by '#' |
Environment variables are visible by root users, consider avoid this usage on production or encode them by using a library like cryptography.
cd src/
python3 main.py
To be able to prompt on Twitch chat, the program needs to be running and the connection with IRC must be established.
The format to make prompts is the following:
!chat inputPrompt
If there are no errors, the bot will answer the prompt quoting the transmitter.
If you want to change the number of characters the GPT will answer, you can do it in the gpt.py
file in the send_request
function, where a limit of 150 characters is specified.
def send_request(self, prompt, limit = 150):
- Implementation of prompt queue to be resolved by the GPT.
- Multithreading to monitor multiple Twitch channels simultaneously.