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.
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).
Login with your github account and fork this repository to get your own copy of it.
Open the file file_context.txt and write down all your background information for GPT.
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.
Go to https://platform.openai.com and create an account.
Initially you will get a free contingent to use but later on you will have to pay for the server usage.
You can set a spending limit here: https://platform.openai.com/account/billing/limits
Go to https://platform.openai.com/account/api-keys
Press "Create new secret key"
Save that secret key somewhere safe.
You will use this key to authorize your version of this chatbot with openai. Treat this as the key to your wallet.
Press the button to deploy this on Cyclic.
Log in with your Github account there and select your twitch-chatgpt repository for deployment.
The standard cyclic account is free to use and only very big streams will run into issues with their request contingent.
Go to the variables tab in your deployment.
Create 3 new variables. The exact spelling of these variables is important:
Accepts one of 2 values:
"CHAT" - Chat mode with history, cheaper then prompt mode but also faster. Uses gpt-3.5-turbo as model.
"PROMPT" - Prompt mode, no history. Uses text-davinci-003 as model.
Only works when GPT_MODE is CHAT
Accepts a number.
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.
This is where you paste your openAI Secure Key.
Save the Changes.
Copy the link cyclic provides for you.
You can find it in the top left corner below the title of your deployed repository.
Now it is time to build your Chat-Command.
Go to your Streamelements Dashboard -> Chatbot -> Commands -> Custom Commands.
Create a new command.
Enter the following in the response field:
$(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.
Go to your commands page and add a new command.
Enter the following in the message field:
$(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.