Skip to content
Open

Main #63

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
225 changes: 85 additions & 140 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,203 +1,148 @@
Your support means the world to me! :heart:
# ChatGPT Twitch Bot Documentation

**Important Notice: Cyclic is no longer supported for deployment. Please use Render for deploying this bot.**

Your support means the world to me! ❤️

☕ [Buy me a coffee to support me](https://www.buymeacoffee.com/osetinhas) ☕

# ChatGPT Twitch Bot
Join our Discord community:

[https://discord.gg/pcxybrpDx6](https://discord.gg/pcxybrpDx6)

This is a simple Node.js Chat bot with ChatGPT Integration based on the simplest possible nodejs api using express that responds to any request with: Yo!
---

It considers a context file for every message so you can give it background information about your stream, your socials, your stream rewards, stream currency and so on.
## Overview

You can choose if you want it to run in prompt mode (without context of previous messages) or in chat mode (with context of previous messages).
This is a simple Node.js chatbot with ChatGPT integration, designed to work with Twitch streams. It uses the Express framework and can operate in two modes: chat mode (with context of previous messages) or prompt mode (without context of previous messages).

# How to use
## Features

## 1. Fork this on Github
Login with your github account and fork this repository to get your own copy of it.
- Responds to Twitch chat commands with ChatGPT-generated responses.
- Can operate in chat mode with context or prompt mode without context.
- Supports Text-to-Speech (TTS) for responses.
- Customizable via environment variables.
- Deployed on Render for 24/7 availability.

---

## 2. Fill out your context file
Open the file file_context.txt and write down all your background information for GPT.
## Setup Instructions

The contents of this file will be sent every time somebody enters your chat command. This will increase the cost of every request with every word you put in, but can still be pretty lengthy.
### 1. Fork the Repository

---
Login to GitHub and fork this repository to get your own copy.

## 3. Create an openAI account
Go to https://platform.openai.com and create an account.
### 2. Fill Out Your Context File

Initially you will get a free contingent to use but later on you will have to pay for the server usage.
Open `file_context.txt` and write down all your background information for GPT. This content will be included in every request.

You can set a spending limit here: https://platform.openai.com/account/billing/limits
### 3. Create an OpenAI Account

---
Create an account on [OpenAI](https://platform.openai.com) and set up billing limits if necessary.

## 4. Get your openAI Secure Key
Go to https://platform.openai.com/account/api-keys
### 4. Get Your OpenAI API Key

Press "Create new secret key"
Generate an API key on the [API keys page](https://platform.openai.com/account/api-keys) and store it securely.

Save that secret key somewhere safe.
### 5. Deploy on Render

You will use this key to authorize your version of this chatbot with openai.
<strong>Treat this as the key to your wallet.</strong>
Render allows you to run your bot 24/7 for free. Follow these steps:

---
#### 5.1. Deploy to Render

Click the button below to deploy:

## 5. Deploy this repo on Cylic or Render for free
[![Deploy to Render](https://render.com/images/deploy-to-render-button.svg)](https://render.com/deploy)

Render is the latest addition to our repo. With Render you can have a server running 24 hours a day for free.
You **WON'T** need to use NIGHTBOT or STREAMELEMENTS to host your bot anymore!
By default the messages will be answered by a bot called *oSetinhasbot* but you can change it to your own bot name.
Check
#### 5.2. Login with GitHub

Cyclic is our old approach with certain limitations. You can still use it if you want to.
You will have to use NIGHTBOT or STREAMELEMENTS to host your bot, and they have a **10seconds timeout**.
Also, Twitch has a **400 character limit** on chat messages, so you will have to use the !continue command to continue a conversation.
Log in with your GitHub account and select your forked repository for deployment.

Press the button to deploy this on Cyclic or Render.
### 6. Set Environment Variables

### 5.1. Deploy to Render
Go to the variables/environment tab in your Render deployment and set the following variables:

[![Deploy to Render](https://render.com/images/deploy-to-render-button.svg)](https://render.com/deploy)
#### 6.1. Required Variables

### 5.2. Deploy to Cyclic

[![Deploy to Cyclic](https://deploy.cyclic.app/button.svg)](https://deploy.cyclic.app/)
- `OPENAI_API_KEY`: Your OpenAI API key.

### 5.3. Login with Github
#### 6.2. Optional Variables

Log in with your Github account there and select your twitch-chatgpt repository for deployment.
##### 6.2.1. Nightbot/Streamelements Integration Variable
- `GPT_MODE`: (default: `CHAT`) Mode of operation, can be `CHAT` or `PROMPT`.

These services are free to use and only very big streams will run into issues with their request contingent.
##### 6.2.2. All Modes Variables
- `HISTORY_LENGTH`: (default: `5`) Number of previous messages to include in context.
- `MODEL_NAME`: (default: `gpt-3.5-turbo`) The OpenAI model to use. You can check the available models [here](https://platform.openai.com/docs/models/).
- `COMMAND_NAME`: (default: `!gpt`) The command that triggers the bot. You can set more than one command by separating them with a comma (e.g. `!gpt,!chatbot`).
- `CHANNELS`: List of Twitch channels the bot will join (comma-separated). (e.g. `channel1,channel2`; do not include www.twitch.tv)
- `SEND_USERNAME`: (default: `true`) Whether to include the username in the message sent to OpenAI.
- `ENABLE_TTS`: (default: `false`) Whether to enable Text-to-Speech.
- `ENABLE_CHANNEL_POINTS`: (default: `false`) Whether to enable channel points integration.
- `COOLDOWN_DURATION`: (default: `10`) Cooldown duration in seconds between responses.

---
#### 6.3. Twitch Integration Variables

## 6. Set your environment variables
Go to the variables/environment tab in your deployment.

Create 3 new variables. The exact spelling of these variables is important:

### 6.1. Required Variables for both Render and Cyclic

1. _**OPENAI_API_KEY**_
- This is where you paste your openAI Secure Key.

### 6.2 Required Variables only for Render

2. _**CHANNELS**_
- This is where you put your twitch channel name.
- If you have more than one channel, separate them with a comma. (e.g. channel1,channel2,channel3)
- If the channel has FOLLOWERS-ONLY mode enabled:
- create a GitHub issue requesting "oSetinhasBot" account to follow your channel.
- connect your own account, see variable 7. and 8.

### 6.2. Optional Variables for both Render and Cyclic

3. _**GPT_MODE**_
- (default: CHAT)
- Accepts one of 2 values:
- "CHAT" - Chat mode with history, cheaper than prompt mode but also faster. Uses gpt-3.5-turbo as model.
- "PROMPT" - Prompt mode, no history. Uses text-davinci-003 as model.

4. _**HISTORY_LENGTH**_
- (default: 3)
- Accepts a number.
- Only works when GPT_MODE is CHAT
- Defines how many bot-user conversations will be saved and sent together with the most recent user message.
- This gives ChatGPT the ability to remember things and allow conversations instead of static prompts.

5. _**MODEL_NAME**_
- (default: gpt-3.5-turbo)
- Accepts one of 2 values:
- "gpt-3.5-turbo" - The default model. This is the fastest and cheapest model. It is also the least accurate.
- "text-davinci-003" - Most expensive model.
- "gpt-4" - Most accurate model and if you have the plan for it!

6.3. Optional Variables only for Render

6. _**COMMAND_NAME**_
- (default: chat) (so the command is !chat)
- Accepts a string.
- Defines the command that will be used to trigger the bot.

7. _**TWITCH_USER**_
This step can be complicated.
- To get the necessary twitch user:
- Go to https://dev.twitch.tv/console
- Register your application
- Fill a name for your application (this can be anything)
- Set OAuth Redirect URL to https://twitchapps.com/tokengen/
- Set Category to Chat Bot
- Set Description to anything you want
- Fill the TWITCH_USER variable with the name of your application

8. _**TWITCH_AUTH**_
- `TWITCH_AUTH`: OAuth token for your Twitch bot.
- Go to https://twitchapps.com/tmi/ and click on Connect with Twitch
- Copy the token from the page and paste it in the TWITCH_AUTH variable
- ⚠️ THIS TOKEN MIGHT EXPIRE AFTER A FEW DAYS, SO YOU MIGHT HAVE TO REPEAT THIS STEP EVERY FEW DAYS ⚠️

Save the Changes.
### 7. Text-To-Speech (TTS) Setup

## 7. Text-To-Speech (TTS) Connection
Your Render URL (e.g., `https://your-twitch-bot.onrender.com/`) can be added as a widget to your stream for TTS integration.

Your render url, for example:
- https://your-twitch-bot.onrender.com/
---

You will see the following web page, and it is directly connected to your twitch chat.
## Usage

You can add it to your stream as a widget :)
### Commands

![img.png](imgs/img.png)
You can interact with the bot using Twitch chat commands. By default, the command is `!gpt`. You can change this in the environment variables.

---
### Example

If you used RENDER, you can stop here :)
To use the `!gpt` command:

---
```twitch
!gpt What is the weather today?
```

## 7. Get your API Link from Cyclic
Copy the link cyclic provides for you.
The bot will respond with an OpenAI-generated message.

You can find it in the top left corner below the title of your deployed repository.
### Streamelements and Nightbot Integration

---
#### Streamelements

## 8. Add your API Command to your Chatbot
Now it is time to build your Chat-Command.
Create a custom command with the response:

```twitch
$(urlfetch https://your-render-url.onrender.com/gpt/"${user}:${queryescape ${1:}}")
```

### Streamelements
Go to your Streamelements Dashboard -> Chatbot -> Commands -> Custom Commands.
#### Nightbot

Create a new command.
Create a custom command with the response:

Enter the following in the response field:
```twitch
!addcom !gptcmd $(urlfetch https://twitch-chatgpt-bot.onrender.com/gpt/$(user):$(querystring))
```
$(urlfetch https://your-cyclic-url.app/gpt/"${user}:${queryescape ${1:}}")
```
Replace "your-cyclic-url.app" with the url you copied in step 7

Enjoy your command.
Replace `your-render-url.onrender.com` with your actual Render URL.
Replace `gptcmd` with your desired command name.
Remove `$(user):` if you don't want to include the username in the message sent to OpenAI.
---

## Support

### Nightbot
Go to your commands page and add a new command.
For any issues or questions, please join our [Discord community](https://discord.gg/pcxybrpDx6).

Enter the following in the message field:
Thank you for using the ChatGPT Twitch Bot! Your support is greatly appreciated. ☕ [Buy me a coffee](https://www.buymeacoffee.com/osetinhas) ☕

```bash
$(eval "$(urlfetch https://your-cyclic-url.app/gpt/"$(user):$(querystring)")"; ' ')
```
Replace "your-cyclic-url.app" with the url you copied in step 7

Enjoy your command.
---

## Extra commands
### Important Notice

### !continue
Twitch has a 400 character limit on chat messages.
If you want to continue a conversation, you can use the !continue command.
**Cyclic is no longer supported for deployment. Please use Render for deploying this bot.**

$(urlfetch https://your-cyclic-url.app/continue")
---
20 changes: 0 additions & 20 deletions file_backup

This file was deleted.

12 changes: 6 additions & 6 deletions file_context.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Never begin your sentences with "!" or "/".
Try to make a joke here and there.
Dont engage into talks about politics or religion. Be respectful towards everybody.

Your name is:
The name of the stream is:
The streamer is called:
The stream community members are called:
The stream currency is called:
Your name is: XTAKA
The name of the stream is: KEBAB CODE
The streamer is called:TAKA
The stream community members are called:CHAT
The stream currency is called:JUST IS LEAGUE
The streamer can be found under the following socials and links:
TikTok:
Youtube:
Youtube:https://www.youtube.com/@NORTHST4R
Twitter:
Facebook:
Instagram:
Expand Down
Loading