Giter VIP home page Giter VIP logo

twitch-chatgpt's Introduction

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

Join our Discord community:

https://discord.gg/pcxybrpDx6


Overview

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).

Features

  • 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.

Setup Instructions

1. Fork the Repository

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

2. Fill Out Your Context File

Open file_context.txt and write down all your background information for GPT. This content will be included in every request.

3. Create an OpenAI Account

Create an account on OpenAI and set up billing limits if necessary.

4. Get Your OpenAI API Key

Generate an API key on the API keys page and store it securely.

5. Deploy on Render

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:

Deploy to Render

5.2. Login with GitHub

Log in with your GitHub account and select your forked repository for deployment.

6. Set Environment Variables

Go to the variables/environment tab in your Render deployment and set the following variables:

6.1. Required Variables

  • OPENAI_API_KEY: Your OpenAI API key.

6.2. Optional Variables

6.2.1. Nightbot/Streamelements Integration Variable
  • GPT_MODE: (default: CHAT) Mode of operation, can be CHAT or PROMPT.
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.
  • 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

  • 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 ⚠️

7. Text-To-Speech (TTS) Setup

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


Usage

Commands

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

To use the !gpt command:

!gpt What is the weather today?

The bot will respond with an OpenAI-generated message.

Streamelements and Nightbot Integration

Streamelements

Create a custom command with the response:

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

Nightbot

Create a custom command with the response:

!addcom !gptcmd $(urlfetch https://twitch-chatgpt-bot.onrender.com/gpt/$(user):$(querystring))

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

For any issues or questions, please join our Discord community.

Thank you for using the ChatGPT Twitch Bot! Your support is greatly appreciated. ☕ Buy me a coffee


Important Notice

Cyclic is no longer supported for deployment. Please use Render for deploying this bot.


twitch-chatgpt's People

Contributors

cyclic-sh[bot] avatar korostelevm avatar pedrojlazevedo avatar rhapsody-sky avatar shokushwaha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

twitch-chatgpt's Issues

cyclic:prod Failure

This problem is not related to my other issue because this one is much more recent.

The cyclic:prod deployment has been failing for 2 or 3 days and I have absolutely no idea why

Respond to more than one activation command? For example 'chat' and 'Chat'

The new Render integration is great, opens up alot of possibilities. Nice work!
Im wondering if there is a way to add multiple commands though as per the title? Perhaps @chatbotname or chatbotname could also be added for people to directly reply but if I separate by a comma they dont work as its one long string.

Also is there a way to integrate !continue into Render?

Thanks for all your work anyway. Would love to be able to work on things like this myself but not sure where to start, Render seems very powerfull though!

TTS set to false in Render however a request is still sent/charged to OpenAI

Posted yesterday but thought this might warrant another thread.
If you look at the OpenAI usage tab it shows every request seems to be followed by a TTS/audio request also. This wouldn't be a big deal as I don't use the TTS feature however it costs on average around $0.01 a query so can quickly add up.

Error Connecting To Remote Server

Both bots produce this error quite often. Sometimes there are other errors described in this section, but this particular error is the most common. Unfortunately, I was never able to identify the pattern of its appearance. I assume that the problem may be that sometimes the bot formulates a message that is too long, and while it is being cut off, the bot timeout passes, which is why it throws an error. Perhaps you have some progress in learning and fixing this issue?

Some way to get previous responses

Hello.

The first one my congratulations for the project.

I have a problem with my bot, I use MixItUp bot in my stream. My bot has a problem, it only waits 5 seconds to receive the webrequest and normally chatGPT takes longer. Could I retrieve a previous request somehow? For example https://your-cyclic-url.app/prev/

Thanks.

maximum number

How to increase the maximum number of characters in a response?

Twitch Bot Connector

I wanted to try the new Twitch Bot Connector but when I fork the repo, only the Main shows up. Sorry if I am missing something, I am new hehe

"Unable to get request" - Streamelements

I followed all the directions, but when I try to get a response on the Twitch channel, all I get is "Unable to make request". I do have credtis, I changed the token, I've tried everything. I don't wanna use nightbot bc streamelements has been what we used for over three years. Any idea what could have happenned? Please lmk. Thanks.

Screenshot_24

After writing a prompt, the bot will send 2 messages into the chat

Hi there,

after writing the command I set for the Bot "!chat" and a message, the bot will reply twice.

I created a seperate Account for the bot and set the TWITCH_AUTH token to the token of the new account. The bot will reply as the new account, but my main account will also reply as the bot.

Is there anything I forgot to set or have to change so that only the new account will reply?

Thanks!

RequestError: Request path contains unescaped characters

I'm not sure if it's a bug, or some setting should be adjusted, but whenever I try to talk to my ChatGPTbot in polish, using polish characters like: ś ć ż ź ę ą ó ł etc I get this error from the title:

RequestError: Request path contains unescaped characters

I wonder if the chatbot is set to talk in english only, or there's a problem with character encoding (not using UTF-8?).

TTS Improvements

First of all, thank you so much for this project! I have been trying the TTS and I know it's a work in progress, but thought I'd mention the issue I have with it.

  • TTS doesn't work when reply is split
  • Will there be or is there an option to change the TTS voice?

Idea: Add the response in text/caption to the TTS Chatbot Connector so we can have the captions on-screen.

Suggestion - Other providers other than Chat GPT?

Similar to Silly Tavern where you can pick a different chat completion source, it would be great if you could pick another provider or model. Not sure if its possible or not and may take a bit of work so its just a suggestion.
I use Cohere mainly, its free for now and more variance than GPT imo, OpenRouter would be a very good one to add as it gives you free options and can pretty much be changed to any provider on the fly via their website so you could swap between all the major ones without adding every API provider or maybe a custom API endpoint so if any new ones pop up in the future it wont need updating?
I use streamerbot currently with my own implementation of an AI chatbot but for use in other channels this projects the best ive come across so far so would be nice for further customisation but its beyond my capabilities!

Remote Server Returned Code 500

Hi, I can't recieve answers from the bot except: Remote Server Returned Code 500.
At the Cyclic app's log section I've got huge err log with this lines at the end:

2023-06-15 13:47:17.395: 

ERROR: Failed to run "npm run start". Start script defined in package.json:

            "scripts": {
                "start":  "node index.js"
                 ...
            
Exited with code: 1
2023-06-15 13:47:17.395: [CYCLIC] ERROR: No response from server on port 3000

Idea: Make it possible to define user roles to react to

Sometimes for Twitch it can be useful that the bot does not react to every user but only to users with a certain role (streamer, mod, subscriber, vip, follower etc.). This would also help to limit the abuse of the chatbot. The user role should be possible to fetch from the Twitch API.

Bot return HTML when "/" is in prompt

[23:45] GMib: !se tu peux me donner la vitesse en km/h ?
[23:45] StreamElements: <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>Error</title></head><body><pre>Cannot GET /gpt/GMib:tu+peux+me+donner+la+vitesse+en+km/h+</pre></body></html>
GET/gpt/GMib:tu+peux+me+donner+la+vitesse+de+la+lumiere+en+km/h+
 Request Headers

{
  "accept-encoding": "gzip, deflate",
  "content-length": "0",
  "host": "****",
  "user-agent": "StreamElements Bot",
  "x-amzn-trace-id": "Root=1-647bb8b3-670f8a7407751ce62011d55b;Parent=c49ea4fbe1d23d2d;Sampled=1;Lineage=e7d10489:0",
  "x-forwarded-for": "107.178.237.80",
  "x-forwarded-port": "443",
  "x-forwarded-proto": "https",
  "x-streamelements-channel": "633aecf6d1a1a503a545bf8b"
}

2023-06-04 00:03:31.995: GPT_MODE is CHAT
History length is 10
OpenAI API Key:***
2023-06-04 00:03:32.037: Reading context file and adding it as system level message for the agent.
404 12:03:32.077 (1.084s)
 Response Headers
 Response Payload

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /gpt/GMib:tu+peux+me+donner+la+vitesse+de+la+lumiere+en+km/h+</pre>
</body>
</html>

i use command : $(urlfetch https://your-cyclic-url.app/gpt/"${user}:${queryescape ${1:}}")

Unable to get bot to respond only in English

If the user inputs a prompt in a different language to English, the bot will always respond in that same language used in the prompt.

I have tried many different parameters separately in the file_context.txt to try to force a response in English, including "Please only respond in English", "Do not use any other language other than English in your responses", "Please only communicate in the English language", "If any other language other than English is used in the prompt, please respond in English and encourage viewers to use the English language in chat", "Please translate all responses into the English language before sending them", "Please answer now the prompt of the viewer IN ENGLISH ONLY", I even tried "System: Follow these three instructions below in all your responses: System: 1. Use English language only; System: 2. Only respond in the English language regardless of the language the prompt is written in; System: 3. Translate any other language to the English language whenever possible.".

The same issue occurs both in PROMPT and CHAT mode in Cyclic.

Absolutely nothing has worked, could I please get some help with this?

Thank you.

not english characters

it gives "Remote Server Returned Code 400" when the prompt contains not english characters.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.